How the kernel sees a process

% From the kernel point of view, a process is an entry in the process table. Nothing more. The process table, then, is one of the most important data structures within the system, together with the memory-management tables and the buffer cache. The individual item in the process table is the <#2445#> task_struct<#2445#> structure, quite a huge one, defined in <#2446#> include/linux/sched.h<#2446#>. Within the <#2447#> task_struct<#2447#> both low-level and high-level information is kept--- ranging from the copy of some hardware registers to the inode of the working directory for the process. The process table is both an array and a double-linked list, as well as a tree. The physical implementation is a static array of pointers, whose length is <#2448#> NR_TASKS<#2448#>, a constant defined in <#2449#> include/linux/tasks.h<#2449#>, and each structure resides in a reserved memory page. The list structure is achieved through the pointers <#2450#> next_task<#2450#> and <#2451#> prev_task<#2451#>, while the tree structure is quite complex and will not be described here. You may wish to change <#2452#> NR_TASKS<#2452#> from the default value of 128, but be sure to have proper dependency files to force recompilation of all the source files involved. After booting is over, the kernel is always working on behalf of one of the processes, and the global variable <#2453#> current<#2453#>, a pointer to a <#2454#> task_struct<#2454#> item, is used to record the running one. <#2455#> current<#2455#> is only changed by the scheduler, in <#2456#> kernel/sched.c<#2456#>. When, however, all processes must be looked at, the macro <#2457#> for_each_task<#2457#> is used. It is considerably faster than a sequential scan of the array, when the system is lightly loaded. A process is always running in either ``user mode'' or ``kernel mode''. The main body of a user program is executed in user mode and system calls are executed in kernel mode. The stack used by the process in the two execution modes is different---a conventional stack segment is used for user mode, while a fixed-size stack (one page, owned by the process) is used in kernel mode. The kernel stack page is never swapped out, because it must be available whenever a system call is entered. System calls, within the kernel, exist as C language functions, their `official' name being prefixed by `<#2458#> sys_<#2458#>'. A system call named, for example, <#2459#> burnout<#2459#> invokes the kernel function <#2460#> sys_ burnout ()<#2460#>.

#tex2html_wrap2952#