Site icon DesignLinux

Ps Command in Linux (List Processes)

Ps Command in Linux (List Processes)

A process is an executing instance of a program. Process is one of the important concept of the Linux OS. Linux provides ps utiliy to view information about running processes. In this article, we will show you how to use the ps command to list the currently running processes and their PIDs along with other information.

How to Use ps Command

The basic syntax for the ps command is as follows:

ps [OPTIONS]

ps provides numerous options for manipulating the output according to our need.

You can use different options types simultaneously, but in some specific situation conflicts can appear.

If using ps command without any options it will show four columns by default. It will show minimum two processes running in the current shell.

ps
 PID TTY          TIME CMD
4402 pts/0    00:00:00 bash
4412 pts/0    00:00:00 ps

The above output shows information about shell (bash) and and the processes that run in the shell (ps).

You can see there are four columns PID, TTY, TIME and CMD.

The ps command accepts many more options that can be used to display a specific group of processes and different information about the process. ps is most frequently used with the following combination of options:

BSD form:

ps aux

Here, combination of three options:

The above command will show the output in eleven columns as given below:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.4 159668  8932 ?        Ss   Jun19   0:03 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jun19   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        I    Jun19   0:00 [kworker/0:0]
...

Below is an explanation of labels, we already shown PID, TTY, TIME and CMD labels before:

You can use the -f option to show a tree view of parent to child processes:

ps auxf

UNIX form:

ps -ef

The command will show output in eight columns named UID, PID, PPID, C, STIME, TIME, and CMD:

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Jun19 ?        00:00:03 /sbin/init
root         2     0  0 Jun19 ?        00:00:00 [kthreadd]

Following is the explanation of remaining labels:

To show the processes running of a specific user, you would type:

ps -f -U tecnstuff -u tecnstuff

Here, tecnstuff is the user name.

Specific Format

You can use o option with ps command to show columns which you want to display.

For example, to display only PID, PPID and COMMAND, you should run one of below command:

ps -efo pid,ppid,comm
ps auxo pid,ppid,comm

Conclusion

The ps command is one of the most frequently used commands when fixing issues on Linux machines. There many options you can use with ps command.

To know more about ps, type man ps in your terminal.

If you have any questions or suggestion, please leave a comment below.

Exit mobile version