Wednesday, June 11, 2014

difference between Kernel Thread and User thread

1. Kernel threads run only in Kernel Mode, while regular processes run alternatively in Kernel Mode and in User Mode.

2. Because kernel threads run only in Kernel Mode, they use only linear addresses greater than PAGE_OFFSET. Regular processes, on the other hand, use all four gigabytes of linear addresses, in either User Mode or Kernel Mode.

Process 0 :
This is the ancestor of all processes, also known as the idle process. it is a kernel thread created from scratch during the intialization phase of linux. This ancestor proces uses the following statically allocated data structures.

1. A process descriptor stored in the init_task variable, initialized by the INIT_TASK macro.
2. A thread_info descriptor and a Kernel Mode stack stored in the init_thread_union variable and initialized by the INIT_THREAD_INFO macro.
3. The following tables, which is the process descriptor points to:

- init_mm ( initialized by INIT_MM)
- init_fs (initlialized by INIT_FS)
- init_files (initlialized by INIT_FILES)
- init_signals(initialized by INIT_SIGNALS)
- init_sighand(initialized by INIT_SIGHAND)

4. The master kernel Page Global Directory stored in swapper_pg_dir.

The start_kernel() function intializes all the data structures needed by the kernel enables interrupts, and creates another kernel thread, named process 1 (known as init process).

After creating init process, Process 0 is selected by scheduler only when there are no other processes in the TASK_RUNNING state.

For multiprocessor system, there is a process 0 for each CPU.

No comments: