Processes are the one of the main parts of the operations systems. All user side even kernel side operations are executed with process. 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 most used command to list and get information about processes.
List Current User Processes
Process can be listed without providing any option to the
ps command. But this will only list current users processes and do not list other system, user or root user processes.
ps command is very universal tool.
ps also used other Unix variant operations systems. BSD provides options without
- dash. So there is generally no difference but knowing BSD Syntax is beneficial. Following example uses BSD syntax.
List All Process
In previous steps we have listed the processes running on the Linux system just for current user. 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
PIDshow process ID
TTYshow running console
TIMEshow the used CPU time
CMDshow the complete command the thread number
List Processes As Tree
In previous example we have printed all processes in list format. There is alternative presentation format named Tree. Tree format is an 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 process. We will use
-u option for this detailed information.
$ ps -A l
UIDshow the User ID of process
PIDshows the process ID
PPIDshows the Parent Process ID
PRIshows Process nice value
STATshows the current status of the process
TTYshows 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 username to filter.
In this example we want to filter username
$ ps -u ismail
Display Threads of Process
As we know Linux provides threads to make processes more efficient. Threads are create under the processes and completes given work by 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 is alternatives to sort processes. We can sort processes according 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 same as
top command. We will use an external command named
watch and provide the
In this example we will list processes in 2 second intervals.
$ watch -n 2 ps