This article provides a deep dive into the Linux
ps
command, explaining its history, when and why it is used, and providing a comprehensive guide on its usage. Despite being direct and simple, understanding this command and the information it provides is crucial for effective system administration in Linux.
Instructions
This article dives deep into the Linux ps
command. It discusses its history, when and why to use it, and offers a comprehensive guide on how to use it. The article also outlines some tricks, points of caution, and concludes with a concise wrap-up of the ps
command.
History
The ps
command is a traditional Unix command that has been an integral part of Unix/Linux systems for decades and serves as a crucial tool for process management and system diagnosis.
When and why to use it
The ps
command is used when you want to view information about processes running on a Unix/Linux system. It is essential for managing system resources, diagnosing issues, and understanding system behavior.
How to use it
The ps
command can be used without any options to list processes that belong to the current user and are associated with the terminal where the command is run.
$ ps
PID TTY TIME CMD
3078 pts/0 00:00:00 bash
The commonly used parameters
-e
or-A
: To display information about all the processes running on the system.
$ ps -e
PID TTY TIME CMD
1 ? 00:00:02 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:04 kworker/0:0
-f
: To display additional information (full-format listing) about the processes.
$ ps -f
UID PID PPID C STIME TTY TIME CMD
root 3078 3067 0 08:06 pts/0 00:00:00 bash
Other supported parameters
-l
: Displays a long listing format.-j
: Provides information related to jobs.-a
: Includes processes from all users.-u
: Includes user-oriented format.-x
: Includes processes not attached to a terminal.
Most common use cases
One of the most common use cases for the ps
command is to monitor the system for resource-intensive processes.
$ ps -aux --sort=-%mem | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1224 8.3 15.6 5660568 3187532 ? Sl Feb21 602:54 /usr/bin/dockerd -H fd://
The tricky skills
A trick to use with the ps
command is to pipe its output into grep
to search for specific processes.
$ ps aux | grep python
root 2389 0.1 0.7 219932 15356 pts/0 S+ 11:27 0:00 python script.py
What needs to be noted
The output of the ps
command can be quite extensive, especially on a busy system. Use the less
or more
commands to page through the output.
Conclusion
The ps
command is a powerful and versatile tool for managing and diagnosing Linux systems. Understanding its usage and the information it provides is key to effective system administration.