Wednesday, March 28, 2012

Processes and Threads in Linux


Data Structures The Linux kernel uses a process descriptor, which is a data structure of type task. struct, to contain all information pertaining to a process or thread. For a process, this data structure contains the process state, information about its parent and child processes, the terminal used by the process, its current directory, open files, the memory allocated to it, signals and signal handlers.

The kernel creates sub-structures to hold information concerning the terminal, directory, files, memory and signals and puts pointers to them in the process descriptor. this organization saves both memory and overhead when a thread is created.

Creation and terminaton of processes and threads Linux supports the system calls fork and vfork whose functionalities are identical to the corresponding Unix calls. These functionalities are actually implemented by the system call clone which is hidden from the view of programs. Both processes and threads  are created this way, the only difference is in the flags passed to the clone call as a parameter, which purposess; effectively, the Linux threads are kernel - level thread.

Parent-child relationships Information about parent and child processes or threads is stored in a task.struct to maintain awareness of the process tree. task.struct contains a pointer to the parent and to the deemend parent, which is a process to whom termination of this process should be reported if its parent process has terminated, a pointer to the youngest child, and pointers to the younger and older siblings of a process. Thus, the process tree of Figure 3.2 would be represented as shown in Figure.

No comments:

Post a Comment