What is a TASK_KILLABLE state in Linux ?

ABOUT TASK_KILLABLE state

TASK_KILLABLE sleeping state.

Like most versions of Unix, Linux has two fundamental ways in which a process  can be put  to sleep. A
process which is placed  in the TASK_INTERRUPTIBLE  state  will sleep  until  either (1)  something
explicitly wakes it up, or (2) a non-masked signal is received. The TASK_UNINTERRUPTIBLE state, instead,
ignores signals; processes in that  state will  require an  explicit wakeup  before they  can run
again.   There are  advantages and  disadvantages to  each  type of sleep. Interruptible sleeps enable
faster response to signals, but they  make   the  programming   harder.  Kernel  code   which  uses
interruptible sleeps must always check to see whether it woke up as a result  of a signal, and, if  so,
clean up whatever  it was doing and return  -EINTR back  to user space.  The user-space  side, too,
must  realize  that  a  system  call was  interrupted  and  respond accordingly;  not all  user-space
programmers  are known  for their diligence in this regard. Making a sleep uninterruptible eliminates
these problems, but at the cost of being, well, uninterruptible. If the expected  wakeup event does  not
materialize, the  process will wait forever and there is usually nothing that anybody can do about
it  short  of rebooting  the  system. This  is  the  source of  the dreaded, unkillable process  which is
shown to be  in the "D" state by ps.


TASK_KILLABLE behaves like  TASK_UNINTERRUPTIBLE with the exception that fatal signals will interrupt the sleep.

TYPICAL PART OF A HEADER FILE RELATED (include/linux/sched.h)
[text]
/* Convenience macros for the sake of set_current_state: */
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)

#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
[/text]

LINKS
https://lwn.net/Articles/288056/
https://www.ibm.com/developerworks/linux/library/l-task-killable/
https://elixir.bootlin.com/linux/latest/ident/TASK_KILLABLE
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L90

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s