Process States and Context
Process States
There are 5 states a process can be in
TASK_RUNNING
- The process is either currently running or on a run-queue waiting to run
TASK_INTERRUPTIBLE
- The process is sleeping, waiting for some condition to be true. When the condition is true, the process state is set to
TASK_RUNNING
. It can also awake and become runnable if it receives a signal
- The process is sleeping, waiting for some condition to be true. When the condition is true, the process state is set to
TASK_UNINTERRUPTIBLE
- Same as
TASK_INTERRUPTIBLE
, but does not wake up and become runnable if it receives a signal
- Same as
__TASK_TRACED
- This process is being traced by another process such as
ptrace
- This process is being traced by another process such as
__TASK_STOPPED
- Process execution has stopped, and is not eligible to run
The process state can be manipulated by the function call set_task_state(task,state)
Process Context
A program code is read in from an executable file, and it is executed within the program's address space
Normal process execution happens in user-space
When the program executes a system call, or triggers an exception, it enters kernel-space. The kernel is then said to be executing on behalf of the process, and the kernel is now in process context
Process Family Tree
Kernel starts init
at the end of its boot sequence
init
runs all the initscripts
which runs all the daemons, before the system is "completely" booted up
All processes have a parent which can be accessed in the task_struct
named parent
The init
task process descriptor is statically allocated as init_task
, which can be accessed by running
for (task = current; task != &init_task; task = task->parent);
/* task now points to init */