PS Command in Linux: Top 5 Practical Examples
Introduction.
The Linux ps command, which stands for “process status,” is used primarily to track all running processes in a Linux server and help to manage them. It comes with a bunch of ARGS with it, which have their own functionality to visualize the outcome. For example, the most commonly used command is ps -aux the production line.
It is important for Linux administrators to know how the ps command works in Linux.
Linux runs multiple processes and applications simultaneously, each generating unique PIDs.
Some PIDs can consume more resources than expected, causing system problems.
With too many processes running in the background, identifying the resource-hungry one is difficult.
In such cases, the ps command is a lifesaver to filter output and find the exact issue.
It helps administrators debug and resolve problems efficiently.
Uses of the ps command:
Sorting CPU and Memory Utilizations in the ps Command:
While using a Linux system, the multiple processes that are running in the background utilize memory and CPU, but most of the Linux geeks don’t know that they can sort the utilization using the ps command directly.
Here is an example for memory and CPU utilization output:

In the above example, the ps command uses the inbuilt sort parameter to sort. the utilization from high to low for both CPU and memory.
Here is the breakdown:
ps aux: This is the core command. It lists all processes running on the system.--sort: Command can sort output from high to low for specified percent level.%mem / %cpu: Specify the column to sort by percentage.head: To list only the top 10 processes.
ps command for User-Specific Processes.
Sometimes we just require some specific user processes, but most commonly people use grep in the ps command, but instead of using grep, we can use which, ps -f -u <username> which shows us more specific output than grep because grep may also contain the content that has a similar string pattern in the normal ps output.
In the below output it is mentioned what processes are running by user nginx in the system.

Here is the breakdown:
ps: regular ps command.-f: specify full format The output contains all necessary information. required to get process information.-u nginx: the specific user for whom you want to get specific information.--forest (Optional): shows all child processes in tree format.
ps command for multi-process lists.
When a multi-process application utilizes resources, it is required to check how many worker threads an application is running and to analyze their resource usage and parent-child relationships. It helps to manage machine resources and helps to maintain costs on the cloud platform. by setting only the required hardware configuration.

Find the parent process ID for multi-process scripts:
When executing multi-process scripts, they can continuously spawn multiple child processes. To determine which process initiated them, we need to check their parent process ID (PPID). The ps command offers options to display the PPID of any child process and list it accordingly.
Here is an example command that shows the parent process ID for the process:
[root@linuxhardened ~]# ps -f -o ppid=,cmd= -p 694
1 php-fpm: master process (/etc/php-fpm.conf)
[root@linuxhardened ~]#
However, when searching for the PPID using the application name, you can customize the ps command with basic shell parameters and syntax.
[root@linuxhardened ~]# ps -f -o ppid=,cmd= -p $(ps aux | grep <your command> | grep -v grep | awk '{print $2}' | xargs) | sort -u

Here is the breakdown:
ps aux– Lists all running processes with details including user, PID, CPU/memory usage, and command.grep <your command>– Filters only the processes matching your application or script name.grep -v grep– Excludes thegrepcommand itself from the results to avoid false matches.awk '{print $2}'– Extracts the PID (second column) of each matched process.xargs– Converts the list of PIDs into arguments for the outerpscommand.ps -f -o ppid=,cmd= -p <PID(s)>– Displays the PPID and command for the specified PID(s).sort -u– Removes duplicates and sorts the output, showing unique parent process IDs.
Forcefully Kill Processes Matching a Pattern Using the ps Command:
In Linux there are multiple applications or scripts running in the backend, which makes multiple processes and utilizes resources. Sometimes the application process utilizes many resources, which impacts system performance, and to prevent downtime before the machine crashes due to load or memory, we must stop the application or script that is consuming resources. To stop the application we use, some processes might not run through systemd. In such scenarios we have to forcefully stop the process by using the kill command.
ps aux | grep ^<process_name> | awk '{print $2}' | xargs kill -9
Why use this instead of killing a single process?
Because many applications (like nginx or Java) use multiple worker/child processes, killing a single PID won’t stop them completely. Using ps aux | grep ^<process_name> | awk '{print $2}' | xargs kill -9 ensures all related processes are forcefully terminated at once.
Here is the breakdown:
ps aux– Lists all running processes with details such as user, PID, CPU/memory usage, and command.grep ^<process_name>– Filters only the processes whose command starts with<process_name>to avoid unrelated matches.awk '{print $2}'– Extracts the second column, which is the PID of each matched process.xargs kill -9– Passes all the PIDs tokill -9, forcefully terminating every matched process.
Conclusion:
The ps command in Linux is essential for monitoring and managing processes efficiently. Using these examples, you can track CPU/memory usage, check user-specific processes, and handle multi-process scripts safely.
