Tasks
Tasks represent both processes and threads. Conceptually:
erDiagram
task_struct {
volatile-long state
int prio
pid_t pid
rcu p_opptr
rcu p_opptr
uid_t uid
gid_t gid
uid_t euid
gid_t egid
uid_t fsuid
gid_t fsgid
arrayof-task_struct children
arrayof-task_struct sibling
}
thread_info {
task_struct task
}
task_struct ||--|{ thread_info : "has child threads"
task_struct ||--|{ task_struct : "has child and sibling processes"
task_struct ||--|| task_struct : "has parent process"
- Processes are defined by
task_struct
. - Threads are defined by
thread_info
.
TTY
Each process has an assigned TTY, a device that behaves like a terminal. Nowadays we generally use PTYs provisioned by a service like getty
.
States
The below values are defined in /include/linux/sched.h
. The names are encoded in task_state_array
in /fs/proc/array.c
. Not all of these states are reportable.
Task states
Task states (state
) indicate whether a given task is runnable or not:
stateDiagram-v2
direction LR
[*] --> Ready : Creation
Ready --> Executing : Running
Executing --> Zombie : Termination
Executing --> Ready : Scheduling
Executing --> Interruptible
Executing --> Stopped : Signal
Executing --> Uninterruptible
Stopped --> Ready : Signal
Uninterruptible --> Ready : Signal or event
Interruptible --> Ready : Signal or event
TASK_RUNNING
(R; running) indicates that a task is either running or runnable.TASK_INTERRUPTIBLE
(S; sleeping) indicates a task waiting for time slot or event.TASK_UNINTERRUPTIBLE
(D; disk sleep) wake only when a waited resource becoming available or a timeout occurs.__TASK_STOPPED
(T) indicates a task is suspended and will only handleSIGCONT
(continue) andSIGKILL
(stop).__TASK_TRACED
(t; tracing stop) is the state of a task being traced (via theptrace
system call).TASK_PARKED
(P; parked) is the state of a kthread afterkthread_park()
.TASK_DEAD
task is dead, pending destruction of itstask_struct
. The exit status is inexit_state
.TASK_WAKEKILL
allows a kthread to wake in response to a signal.TASK_WAKING
indicates a task is being woken.TASK_NOLOAD
kthread equivalent ofTASK_UNINTERRUPTIBLE
that doesn't affect the system load average.TASK_NEW
is the state for a newly created task, indicating that it's not yet runnable and cannot wake up in response to a signal or external event.
Exit states
Exit states are independent:
EXIT_DEAD
(X; dead) is the state of a process which has exited, and its parent has waited for it.EXIT_ZOMBIE
(Z; zombie) indicates the process has exited but its parent has not yet awaited its exit.EXIT_TRACE
is a variant ofEXIT_ZOMBIE
for processes under tracing.
procfs
The Process VFS exposes much of this.
References
Backlinks