The ps command in Linux is used to display the status of current processes. It is highly practical as it helps system administrators understand which processes are running, their process IDs (PID), runtime, and resource consumption.
Basic Usage
The basic ps command lists processes associated with the current terminal. For example, simply typing ps will display active processes in the current terminal session.
Displaying Hierarchical View
To display a hierarchical view of processes, we typically use the ps command with specific options. The most common commands are ps -ef or ps aux, both of which display all running processes in the system. However, to display a hierarchical view, we can use ps -ejH or ps axjf.
-
ps -ejH-eindicates displaying all processes.-jindicates displaying information related to job control.-Hindicates displaying in a hierarchical format, making parent-child relationships more apparent.
-
ps axjfaindicates displaying processes from all terminals.xindicates displaying processes even without a controlling terminal.jsimilarly indicates displaying information related to job control.findicates displaying the tree structure using ASCII characters, making hierarchical relationships clearer.
Example
For instance, if we want to view the hierarchical relationships of all processes in the system, we can use the following commands:
bashps -ejH
or
bashps axjf
Both commands output a hierarchical list of processes, including PID, PPID (parent process ID), and the terminal used, with formatted output helping us clearly identify which processes are child processes of others.
This hierarchical view is very helpful for understanding the relationships between various processes in the system, especially during debugging or system optimization, where understanding dependencies between processes is crucial.