Site icon New Generation Enterprise Linux

Explanation of different process states in Linux and how to view or deal with them ?

Today we will look at a very interesting topic to understand various different process states available in Linux.

To understand this post lets look at the command output.

1. ps -aux Command Output showing process states. Look for STAT column.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1   2896  1432 ?        Ss   Aug27   0:01 /sbin/init
root         6  0.0  0.0      0     0 ?        S    Aug27   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Aug27   0:14 [events/0]
root        34  0.0  0.0      0     0 ?        SN   Aug27   0:00 [ksmd]
root        35  0.0  0.0      0     0 ?        S    Aug27   0:00 [aio/0]
root        36  0.0  0.0      0     0 ?        S    Aug27   0:00 [crypto/0]
root       413  0.0  0.1   2948  1244 ?        S

2. Explanation of different STAT column output.

S --> Interruptible sleep(S) process which is waiting for an event to complete.
Ss --> A session leader(s) process in Interruptible sleep(S).
SN --> A low priority(N) process which is nice to others is in interruptible sleep(S).
S "S A multhi-threaded(l) high priority(S A high priroty(SNl --> A low priority(N) multi-threaded(l) process in interruptible sleep(S) state.
SNs --> A low priority(N) session leader(s) process in interruptible sleep(S).
SN+ --> A low priority(N) interruptible sleep(S) process running in foreground(+).
R+ --> A foreground(+) running(R) process.

PROCESS STATE CODES
In the above STAT column, it shows the process state. The different process states of Linux can be found in its MAN page as follows.
PROCESS STATE CODES
       Here are the different values that the s, stat and state output
       specifiers (header "STAT" or "S") will display to describe the state of
       a process.
       D    Uninterruptible sleep (usually IO)
       R    Running or runnable (on run queue)
       S    Interruptible sleep (waiting for an event to complete)
       T    Stopped, either by a job control signal or because it is being
            traced.
       W    paging (not valid since the 2.6.xx kernel)
       X    dead (should never be seen)
       Z    Defunct ("zombie") process, terminated but not reaped by its
            parent.

       For BSD formats and when the stat keyword is used, additional
       characters may be displayed:
       

 

3. Explanation of different Process States.

       
1. Running or Runnable  (R) 
2. Sleeping or waiting
      Interruptible sleep mode (S)
      Uninterruptible sleep mode (D)
3. Stopped (T)
4. Zombie (Z)

1. Running or Runnable (R) : A running process or might be waiting for its turn to process by the scheduler.
2. Sleeping or waiting : A waiting process for some of its sub-task to finish are sent into sleeping state.
Interruptible sleep mode (S) : This sleep mode can be interrupted by us and this process can be killed/changed.
Uninterruptible sleep mode (D) : This sleep mode can't be interrupted and such processes can't be killed explicitly.
3. Stopped (T) : A stopped or suspended process.
4. Zombie (Z) : Those terminated or killed processes(or the processes which has completed their execution) which are not yet cleared from system process table.

4. Sorting Output by process states
This is very useful command and can be helpful to identify a type of processes on system, say zombie processes, uninterruptible sleep process, etc.

[root@nglinux ~]# ps -eo stat,pid,ppid,comm | sort -n -k 1
R+    6917  6616 ps
S        2     0 kthreadd
S        3     2 migration/0
S        4     2 ksoftirqd/0
S        5     2 stopper/0
S        6     2 watchdog/0
S        7     2 events/0
S        8     2 events/0
S        9     2 events_long/0
S       10     2 events_power_ef
S       11     2 cgroup
S       12     2 khelper
S       13     2 netns
S       14     2 async/mgr
S       15     2 pm
S       16     2 sync_supers
S       17     2 bdi-default
S       18     2 kintegrityd/0
S       19     2 kblockd/0
S       20     2 kacpid
S       21     2 kacpi_notify
S       22     2 kacpi_hotplug
S       23     2 ata_aux
S       24     2 ata_sff/0
S       25     2 ksuspend_usbd
S       26     2 khubd
S       27     2 kseriod
S       28     2 md/0
S       29     2 md_misc/0
S       30     2 linkwatch
S       31     2 khungtaskd
S       32     2 lru-add-drain/0
S       33     2 kswapd0
S       35     2 aio/0
S       36     2 crypto/0
S       43     2 kthrotld/0
S       45     2 kpsmoused
S       46     2 usbhid_resumer
S       47     2 deferwq
S       80     2 kdmremove
S       81     2 kstriped
S      172     2 scsi_eh_0
S      173     2 scsi_eh_1
S      204     2 mpt_poll_0
S      205     2 mpt/0
S      206     2 scsi_eh_2
S      210     2 scsi_eh_3
S      308     2 flush-8:16
S      310     2 jbd2/sdb1-8
S      311     2 ext4-dio-unwrit
S      996     2 jbd2/sda1-8
S      997     2 ext4-dio-unwrit
S     1090     2 kauditd
S     1151     2 ib_addr
S     1156     2 infiniband/0
S     1165     2 ib_mcast
S     1170     2 iw_cm_wq
S     1175     2 ib_cm/0
S     1180     2 rdma_cm
S     1201     2 ipoib_flush
S     1518     2 scsi_tgtd/0
S     1519     2 fc_exch_workque
S     1520     2 fc_rport_eq
S     1523     2 fcoe_work/0
S     1525     2 cnic_wq
S     1526     2 bnx2fc
S     1567     1 modem-manager
S     1644  1643 hald-runner
S     1690  1644 hald-addon-inpu
S     1693  1644 hald-addon-acpi
S     1778     1 mysqld_safe
S     2131  2097 httpd
S     2132  2097 httpd
S     2133  2097 httpd
S     2134  2097 httpd
S     2135  2097 httpd
S     2136  2097 httpd
S     2137  2097 httpd
S     2138  2097 httpd
S     2292     1 dbus-launch
S     2304     1 devkit-power-da
S     2358     1 polkitd
S     3805  2144 authatieventsd.
S     3922     1 udisks-daemon
S     3928  3922 udisks-daemon
S     3949  3932 gconf-helper
S     6661  1561 dhclient
S+    6918  6616 sort
S
0 0 votes
Article Rating
Exit mobile version