Processes are one of the main parts of the operations systems. All user side even kernel side operations are executed with the process. The process generally created, run, and killed. This life cycle of the process generally the same. During this life cycle, we may need to get more information about processes. ps command is the most used command to list and get information about processes.
List Current User Processes
The process can be listed without providing any option to the ps command. But this will only list current user’s processes and do not list another system, user, or root user processes.
$ ps

BSD Syntax
ps
command is a very universal tool. ps also used other Unix variant operations systems. BSD provides options without a dash. So there is generally no difference but knowing BSD Syntax is beneficial. The following example uses the BSD syntax.
ps aux
List All Process
In previous steps, we have listed the processes running on the Linux system just for the current users. But generally, we need to list all processes in a single shot. We can provide the -ax
options in order to list all processes.
$ ps -A

PID
show process IDTTY
show running consoleTIME
show the used CPU timeCMD
show the complete command the thread number
List Processes As Tree
In the previous example, we have printed all processes in the list format. There is an alternative presentation format named Tree. Tree format is a hierarchical format which will provide visual information about parent and child relationship.
$ ps -A --forest

List Process Info
While listing processes we can print more information about the process. We will use -u
option for this detailed information.
$ ps -A l

UID
show the User ID of processPID
shows the process IDPPID
shows the Parent Process IDPRI
shows Process nice valueSTAT
shows the current status of the processTTY
shows the current console number if connected
List Only Specific Named Process
While listing processes we may need to filter according to process or command name. Here we will use -C
parameter and process name for filter operation.
$ ps -C acpid
Print Only Specific PID Process
Another way to filter processes id according to their PID. We can filter by given their PID. We will use the -p
option and PID’s in order to filter. In this example, we will filter multiple processes according to their IP address.
$ ps -p 1331,1773

Print Only Specific User Processes
Another useful filtering mechanism is filtering processes according to their owners or users. We will use -u
option and usernames to filter. In this example, we want to filter username ismail
.
$ ps -u ismail

Display Threads of Process
As we know Linux provides threads to make processes more efficient. Threads are created under the processes and complete given work by the parent process. We will use --ppid
option in order to list child threads.
$ ps --ppid 1331
Sort Process According To Cpu Usage
While list process by default they are sorted with their PID’s. There are alternatives to sort processes. We can sort processes according to t their current CPU usage with --sort=pcpu
option like below.
$ ps -A --sort=pcpu
Sort Process According To Memory Usage
We can also sort processes according to their memory usage with --sort=pmem
command like below.
$ ps -aux --sort=pcpu
Run Ps Real Time Mode
The default behavior of ps
command is running and exiting. ps
command can be run in real-time without exiting. This is the same as top command. We will use an external command named watch and provide the ps command. In this example, we will list processes in 2-second intervals.
$ watch -n 2 ps

2 thoughts on “Linux ps Command Tutorial”