The heart of the Linux Kernel: The Process.

Written by Tom on Thursday 09/08/07

A process is a single instantiation of a particular program.

A process like any dynamic enity goes through various states. The process life cycle is thus; It is created, lives

through a variable time span and goes through a number of state changes and then dies as depicted below.

A process is created by a previously existing process with a call to fork();

Forked processes are referred to as the child processes, and the process that creates them is referred to as the parent

process. The child and the parent process continue to run in parrallel. If a parent continues to spawn more children

processes, these processes are sibling processes to the original child. The children may in turn spawn off child

processes of their own. This creates a hierarchial relationship among processes that define their relationship.

Process lifecycle states.

Running: After a process is created it is ready to become a running process.The kernel has set up all the

structures and aquired all necessary information for the CPU to excute the process.

Ready: When a process is prepared to become the running process but has not been selected to run, is in the

ready state.

After a task is running it can:

Be deselected and set back to the ready state by the scheduler.

Be interrupted and placed into a waiting or blocked state.

Become a zombie on its way to process death, which is reached by a call to exit.

A proram contains a number of components that are laid out in memory and acessed by the process that executes the


Text segment: Holds the instructions that are executed by the CPU.

Data segment: Which holds all the data variables manipulated by the proces.

Stack: Which holds automatic variables and function data.

Heap: Which holds dynamic memory allocations.

When a process is created, the child process receives a copy of the parent's data space, heap, stack and process


Process Discriptor

The process discriptor keeps track of information reguarding process interaction with memory management and scheduling

via the task_struct.

The kernel stores all the process discriptors in a circular doubly linked list called the task_list.

The following categories describe some of the things that the process discriptor keeps track of.

Process attributes

Process relationships

Process memory space

Signal management

Process credentials

Resource limits

related fields

Process Creation

A process is created by a call to either fork(), vfork() or clone(). All these system calls

eventually call do_fork(),(with different flags) which is a kernel function that performs the bulk of the

actions related to the process creation.

fork() This function returns twice: once in the parent returning the childs PID and once in the child process

returning 0.

vfork() The same as fork() but the parent process is blocked until the child calls exit() or exec().

clone() Takes a pointer to a function along with its argument.

When the pocess is waiting on an external event to occur, it is removed from the run queue and placed on a wait queue.

A wait queue is a doubly linked list of wait_queue_t structures that hold pointers to the porcess as

structures of the processes that are blocking.

Waking Up

A process must be woken up to verify whether its condition has been met. A process might put itself to sleep but cannot

wake itself up.

I do not claim any originality in this article.
Source: ‘The Linux Kernel Primer’: Claudia Salzberg Rodriguez, Gordon Fisher, Steven Smolski.