Applications 35 – The “ps” Command Part 1 – Simple Process Selection


Jarret W. Buse

Applications 37 – The “ps” Command Part 1 – Simple Process Selection

Every computer system has running applications, services, etc. There may be times that a list of the system processes are needed. A sluggish system may show that too many processes are running. A user may not know what processes are currently active, but shouldn't be running.

Some people may get confused between processes and threads. A process is a single instance of an application on a system. The process uses Random Access Memory (RAM) and the Central Processing Unit (CPU) to function in the Operating System (OS). The programming code, which makes up the program, is executed by the CPU and stored in RAM. Parts of the programming code are executed by the CPU on a schedule. Each part of the code in the schedule is a thread. A program may have multiple threads in the schedule making it a multi-threaded application. Multiple programs on the OS, as well as the OS itself, are in the schedule which is why many programs can be running at once. Even on a single processor system, many applications can operate at once.

So, to see the processes which are running on a Linux system, use the “ps” command. Keep in mind that the command only shows the current instance of operating processes.

NOTE: The use of the “top” command can show the active processes in a continuous state as they change.

The syntax for the “ps” command is “ps [options]”. The options for simple process selection follows with examples.

  • a – The “a” option causes “ps” to list all processes with a terminal (tty), or to list all processes when used together with the x option. Do note that the option has no dash (-) before the option “a” as with all BSD options.
To see the tty processes, use the command “ps a”. The output should be similar to that shown in Figure 1.

Figure 1.jpg


  • -A – Shows all processes. Identical to the “-e” option.

To see all processes running on a system, use the “-A” option. The option produces the same results as the “-e” option. The output should be similar to the partial output in Figure 2.

Figure 2.jpg


  • -a – Select all processes, but not both session leaders and processes not associated with a terminal.

A few terms need to be discussed to understand a session leader. Each Process is assigned a unique ID called a Process ID (PID). A closed application causes the PID to be released so it can be reused by new programs when they are started. If a program starts another program, there is a Parent PID (PPID) which is the PID of the Parent application. A Process Group ID (PGID) is the PID of the Group Leader. Each Process is placed into a Group that share the PGID, or PID of the first process in the Group. The Session ID (SID) is the PID of the Session Leader. When PID equals the SID then the process is a Session Leader.

Figure 3 shows a sample output of the command “ps -a”.

Figure 3.jpg


  • -d – Displays all processes except session leaders.

For a description of “session leader”, see the information for the “-a” option. Here, the list shows all processes, but not the session leaders. For a sample output, see Figure 4.

Figure 4.jpg


  • --deselect – Shows all processes except those that fulfill the specified conditions (negates the selection). The option is identical to the “-N” option.

To create a list of acceptable processes to view, the “-U” option is used (discussed in the next article, “Process Selection by List”). The “--deselect” option causes the opposite of the selection chosen. For example, to select only the processes started by the user “bob”, the command would be “ps -U bob”. To display every process NOT started by “bob” the command would be “ps -U bob --deselect”.

  • -e – Select all processes. Identical to -A.

See the “-A” option above.

  • g – Shows all processes including session leaders. The option may be obsolete in future versions of “ps”.

Do note that the option has no dash (-) before the option “g” as with all BSD options.

  • -N – Displays all processes except those that fulfill the specified conditions (negates the selection). Identical to “--deselect” option.

See the “--deselect” option above.

  • T – Lists all processes associated with this terminal. Identical to the “t” option without any argument.
The “T” or “t” option with no dash shows all processes running in the terminal opened. A sample output is shown in Figure 5. Do note that the option has no dash (-) before the option “T” or “t” as with all BSD options.

Figure 5.jpg


  • r – Limits the listing to only running processes.

There are processes which are actively running and monitoring parts of the system, such as Input or Output. These processes are running all the time. Other processes can go into a “sleep” mode and only activate when needed. If you look at the previous figures, you can see that in some of them, “bash” is running. The “bash” process takes the entered commands and processes them when one is entered. Usually the “bash” command is not always in a “running” state, only when a command is entered does “bash” run.

A sample output of the “r” option is shown in Figure 6. Do note that the option has no dash (-) before the option “r” as with all BSD options.

Figure 6.jpg


  • x – Causes the “ps” command to list all processes owned by the current User.

To see every process running on the system which has the same User ID (UID) as the currently logged-in User use the “x” option. An example listing is shown in Figure 7. Do note that the option has no dash (-) before the option “x” as with all BSD options.

Figure 7.jpg


To see all processes NOT owned by the currently logged-in User, add the “--deselect” option.

Be sure to understand these basic options for the “ps” command before going on to other parts of the “ps” command articles. The options listed here are only the basic options for specifying which processes are listed. Also, be aware that multiple options can be used in a single command.


  • slide.jpg
    32.9 KB · Views: 1,290
Last edited:

Staff online

Members online

Latest posts