Understanding CPU Process States

by Mike on May 23, 2009 · 1 comment

in Server Management

Each program that runs on your computer/server is a process. Understanding how the state, or status, of the process will go a long way in managing your computer/server correctly.  One of the difficult issues of management in Linux is viewing information and then being able to take that information and interpret what it means.  This is certainly the case with processes as the commands to view them powerful and informative but not full of description.  This article provides a simple review of the basic states of processes.  One concept that you need to recognize is that the CPU can only execute one process at a time, so you will see these states vary as processes receive the resources they need and the permission to be runnable.

Each process is listed in a particular state which relates to the process’s ability to receive CPU time.
Runnable process can be executed
Sleeping process waiting for a resource of some kind
Zombie process is trying to die but cannot
Stopped process is suspended and not able to execute

A Runnable process has acquired the resources it needs and is just waiting for the CPU time to execute.  The Sleeping process is often a daemon waiting for terminal input or an established network connection.  The Sleeping process will not get any CPU time until is receives a signal.  Zombies have completed their execution but are still hanging around.  The PPID (Parent Process ID) of a Zombie will help you figure out where they came from.  The Stopped process have been forbidden to run administratively.  This process is waiting for a CONT signal to start up again.

One way you can view these processes is by using the ps command.

When any Linux system is operating there are  hundreds of processes that could be running. A basic understanding of how these processes function is a great advantage to a Linux user. There are a number of ways to view these processes. A common method of viewing processes is by using the terminal. The ps command generates a snapshot of the currently running processes.

The results show several important categories;the user, PID (Process ID), % of CPU usage, % of Memory and the start time. This is an easy way to locate a process that is taking too many resources or too large a percentage of CPU and Memory on the system that can cause all other processes to be very slow. This is a good way to review your system to look for problems.
-a      shows processes used by other users
-u      the user format showing user names and start times
-x      includes processes not started from a terminal like a daemon such as ftp
-f       forest mode, displays process family trees
-l       long format,priority,parent and start time of process
-w     wide output
-C cmd    display an instance of a command
-U user    display processes of specific user

Output Definitions
USER             process owner
PID                process ID
%CPU            % of CPU used by process
%MEM            % of memory used by process
VSZ               virtual size of process
RSS               resident set size or number of pages in memory
TTY              terminal ID
STAT            process state
R – runnable, S – sleeping, Z – zombie, D – uninterruptible sleep, T – stopped
START            time process started
TIME            CPU time consumed
COMMAND        command name

Here is an example of reviewing the samba processes on a server.
ps u -C smbd
root          2626      0.0      0.4     10416     2516     ?            Ss 04:29   0:00     smbd -D
root       2630      0.0      0.4     10416     2488     ?           S 04:29   0:00     smbd -D
root       3701      0.0      0.6     11152     3428     ?            S 04:37   0:00     smbd -D

The “S” shows that these processes are sleeping.

{ 1 comment }

jj May 23, 2009 at 2:58 pm

Very informative site – thanks for your work.

Previous post:

Next post: