Process States and Context


Process States

There are 5 states a process can be in

  1. TASK_RUNNING
    • The process is either currently running or on a run-queue waiting to run
  2. 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
  3. TASK_UNINTERRUPTIBLE
    • Same as TASK_INTERRUPTIBLE, but does not wake up and become runnable if it receives a signal
  4. __TASK_TRACED
    • This process is being traced by another process such as ptrace
  5. __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 */

results matching ""

    No results matching ""