20+ Useful Examples Of Linux PS Command

20+ Useful Examples Of Linux PS Command

Linux ps command is the short form of “Process Status”.  ps command is a command line utility that is used to list the currently running processes and their PIDs. It generates the information from the virtual files in /proc file-system.

The ps the command provides a way to view information about the currently running processes, including their process ID (PID), memory usage, CPU usage, parent process ID (PPID), and other details. For example, the ps aux command can be used to display a detailed list of all running processes, while the ps -ef command can be used to display a more concise list of processes with less detailed information.

ps command option includes:

  • a: Show all processes on the system, including those owned by other users.
  • u: Display user-oriented format with more details.
  • x: Display processes not associated with a terminal.

Table of Contents

1. ps command to display the current process.

ps

2. ps command to display all processes running on the system.

ps -ef

3. ps command to display all processes that match the specified process name.

ps -ef | grep <process-name>

4. Displays all processes that match the specified process name, excluding the grep process itself.

ps -ef | grep <process-name> | grep -v grep

5. Displays all threads for all processes on the system.

ps -eLf

6. Displays the process information for the specified process ID (PID).

ps -p <PID>

7. Displays all processes running on the specified terminal (tty).

ps -t <tty>

8. Displays all processes owned by the specified user.

ps -u <username>

9. Displays all processes running on the system, including system processes.

ps -aux

10. Displays the PID and command name of all running processes.

ps -Ao pid,cmd

11. Displays the PID, command name, CPU usage, and memory usage of all running processes, sorted by CPU usage in descending order.

ps -eo pid,cmd,%cpu,%mem --sort=-%cpu

12. Displays the PID, command name, CPU usage, and memory usage of all running processes, sorted by memory usage in descending order.

ps -eo pid,cmd,%cpu,%mem --sort=-%mem

13. Displays the PID, command name, CPU usage, and memory usage of all running processes, sorted by command name in ascending order.

ps -eo pid,cmd,%cpu,%mem --sort=+cmd

14. Displays the PID, command name, CPU usage, and memory usage of all running processes, sorted by PID in ascending order.

ps -eo pid,cmd,%cpu,%mem --sort=+pid

15. Displays the PID, command name, CPU usage, and memory usage of all running processes, sorted by command name in ascending order, excluding the header line.

ps -o pid,cmd,%cpu,%mem --sort=+cmd | tail -n +2

16. Displays a tree-like view of all processes, showing their parent-child relationships.

ps -e –forest

17. Displays the user name, elapsed time, PID, and command name of all running processes.

ps -o user,etime,pid,cmd

18. Displays the user name, parent PID, PID, CPU usage, memory usage, and command name of all running processes.

ps -o user,ppid,pid,%cpu,%mem,cmd

19. Displays the PID, command name, CPU usage, and memory usage of all processes with the specified parent process ID.

ps -o pid,cmd,%cpu,%mem --ppid <parent-pid>

20. Displays the PID, command name, CPU usage, and memory usage of the specified child process ID.

ps -o pid,cmd,%cpu,%mem --pid <child-pid>

21. Displays all processes with the specified command name.

ps -C <command-name>

22. Displays the PID, command name, CPU usage, and memory usage of all processes with the specified command name.

ps -C <command-name> -o pid,cmd,%cpu,%mem:

23. Displays the PID, command name, memory usage, and CPU usage of the top memory-consuming processes.

ps -e --format pid,cmd,%mem,%cpu --sort=-%mem | head

24. Displays the PID, command name, CPU usage, and memory usage of the top CPU-consuming processes.

ps -e --format pid,cmd,%mem,%cpu --sort=-%cpu | head
ps -e --format pid,cmd,%mem,%cpu --sort=-%cpu | head -n 10

 

Leave a Comment