
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
25 Useful ‘ps Command’ Examples for Linux Process Monitoring
The ‘ps’ command is a popular tool used for monitoring processes in Linux operating system. It stands for ‘process status’ and is used to display information about processes currently running on a system. This information can be useful for troubleshooting, optimizing performance, and identifying potential security issues. In this article, we will discuss 25 useful ‘ps command’ examples for Linux process monitoring.
Display a list of all processes
To display a list of all processes running on a Linux system, use following command −
ps aux
This will display a list of all processes along with their PID (process ID), CPU usage, memory usage, and other relevant information.
Display a list of all processes with full command lines
To display a list of all processes along with their full command lines, use following command −
ps auxf
This will display a tree-like structure of all processes, making it easier to see how they are related.
Display a list of all processes sorted by CPU usage
To display a list of all processes sorted by CPU usage, use following command −
ps aux --sort=-%cpu
This will display a list of all processes sorted in descending order of CPU usage.
Display a list of all processes sorted by memory usage
To display a list of all processes sorted by memory usage, use following command −
ps aux --sort=-%mem
This will display a list of all processes sorted in descending order of memory usage.
Display a list of all processes owned by a specific user
To display a list of all processes owned by a specific user, use following command −
ps -u username
Replace ‘username’ with actual username of user you want to view processes for.
Display a list of all processes for a specific command
To display a list of all processes for a specific command, use following command −
ps -C command
Replace ‘command’ with name of command you want to view processes for.
Display a list of all processes running in a specific terminal
To display a list of all processes running in a specific terminal, use following command −
ps -t tty
Replace ‘tty’ with name of terminal you want to view processes for.
Display a list of all processes in a specific process group
To display a list of all processes in a specific process group, use following command −
ps --pid pgid
Replace ‘pgid’ with process group ID of group you want to view processes for.
Display a list of all child processes for a specific parent process
To display a list of all child processes for a specific parent process, use following command −
ps --ppid pid
Replace ‘pid’ with process ID of parent process you want to view child processes for.
Display a list of all processes with a specific name
To display a list of all processes with a specific name, use following command −
ps -C name
Replace ‘name’ with name of process you want to view.
Display a list of all zombie processes
To display a list of all zombie processes, use following command −
ps aux | awk '$8=="Z" {print}'
Zombie processes are those that have finished executing but have not been properly cleaned up by system.
Display a list of all processes in a specific state
To display a list of all processes in a specific state, use following command −
ps -eo state,pid,user,command | grep state
Replace ‘state’ with state you want to view (e.g. R for running, S for sleeping, Z for zombie).
Display a list of all processes with a specific priority
To display a list of all processes with a specific priority, use following command −
ps -o pid,ppid,user,nice,cmd --sort=-nice
This will display a list of all processes sorted in descending order of priority.
Display a list of all processes with a specific CPU affinity
To display a list of all processes with a specific CPU affinity, use following command −
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm | grep <cpu>
Replace ‘<cpu>’ with CPU you want to view processes for.
Display a list of all processes using a specific port
To display a list of all processes using a specific port, use following command −
sudo lsof -i :port
Replace ‘port’ with port number you want to view processes for.
Display a list of all processes running as a specific user
To display a list of all processes running as a specific user, use following command −
ps -U username -u username u
Replace ‘username’ with name of user you want to view processes for.
Display a list of all processes running in a specific directory
To display a list of all processes running in a specific directory, use following command −
lsof +D /directory
Replace ‘/directory’ with path to directory you want to view processes for.
Display a list of all processes running a specific executable
To display a list of all processes running a specific executable, use following command −
ps -C executable_name
Replace ‘executable_name’ with name of executable you want to view processes for.
Display a list of all processes using a specific file
To display a list of all processes using a specific file, use following command −
lsof /path/to/file
Replace ‘/path/to/file’ with path to file you want to view processes for.
Display a list of all processes with a specific environment variable
To display a list of all processes with a specific environment variable, use following command −
ps -eo pid,user,args | grep -E '^ *PID|^ *[0-9]+ .*VARNAME=VALUE'
Replace ‘VARNAME’ with name of environment variable you want to view processes for, and ‘VALUE’ with its value.
Display a list of all processes using a specific network interface
To display a list of all processes using a specific network interface, use following command −
sudo lsof -i -n -P | grep <interface>
Replace ‘<interface>’ with name of network interface you want to view processes for.
Display a list of all processes with a specific user-defined format
To display a list of all processes with a user-defined format, use following command −
ps -eo pid,user,%cpu,%mem,command --sort=-%mem | head
This will display a list of all processes sorted in descending order of memory usage, using a user-defined format.
Display a list of all processes with a specific memory address
To display a list of all processes with a specific memory address, use following command −
sudo pmap -x pid | grep address
Replace ‘pid’ with process ID of process you want to view memory addresses for, and ‘address’ with memory address you want to view.
Display a list of all processes with a specific user-defined filter
To display a list of all processes with a user-defined filter, use following command −
ps -eo pid,user,%cpu,%mem,command --sort=-%mem | awk '{if ($3 >= 10.0) print $0;}'
This will display a list of all processes using more than 10% of CPU and memory, using a user-defined filter.
Display a tree view of all processes
To display a tree view of all processes, use following command −
pstree
This will display a hierarchical tree view of all processes, with parent process at top and child processes below.
Conclusion
The ‘ps’ command is a powerful tool for monitoring and managing processes in a Linux system. With examples provided in this article, you can easily use ‘ps’ command to view information about running processes, filter and sort output, and perform various other operations. By mastering ‘ps’ command, you can improve performance and stability of your Linux system, and troubleshoot problems more effectively.
- Related Articles
- Linux ps Command
- Linux Process Monitoring
- 25 Practical Examples of Linux Find Command
- 20 Useful Commands of ‘Sysstat’ Utilities for Linux Performance Monitoring
- 25 Useful Linux Commands for System Administrators
- 5 ‘hostname’ Command Examples for Linux Newbies
- 5 ‘stat’ Command Examples for Linux Newbies
- Useful Bandwidth Monitoring Tools to Analyze Network Usage in Linux
- Resuming Process Monitoring for a Process Instance
- Apt Linux Command with Examples
- md5sum Command in Linux with Examples
- 10 Netstat Command Examples on Linux
- AWK Command in Linux with Examples
- 5 Interesting Linux ‘sort’ Command Examples
- Apropos Linux Command Explained {With Examples}
