The ps command is one such tool that displays information related to processes on a Linux system. Let’s look at the ps command and some important examples of usage.
What Is the ps Command?
A process is the basic component of computing in a Linux machine. Every program you open executes one or more processes that are responsible for the working of the computer. From an advanced video editing application to a simple utility like the mv command, everything is comprised of processes.
The ps command, which is an acronym for Process Status, comes in handy when you want to get a list of all the processes running on your system. This command also provides additional information associated with these processes to the user.
How to Use the ps Command in Linux
The basic syntax of the ps command is:
Running the ps command without any arguments produces the following output:
The following information is provided in the aforementioned output.
PID: The process ID of the highlighted process TTY: Displays the name of the terminal that you’re using TIME: The time allotted to the process by the CPU CMD: The command that is responsible for launching the process
List All Processes
To get a list of all the processes on a Linux system, use the -A or -e flag with the default ps command.
View Processes Associated With the Terminal
The -T flag will display the list of all the processes related to the terminal.
You will see an output that looks something like this.
Display Processes Not Associated With the Terminal
The -a flag will list down processes that aren’t associated with the current terminal.
The screen will display an output.
Negate the Specified Options
You can also use the -N or the –deselect flag with the ps command to invert the working of a specific argument.
For example, the -T option displays the processes associated with the terminal. Adding the -N or the –deselect flag with the command will show the processes that are not associated with the current terminal.
Display Custom Columns in the Output
The default ps command displays the following columns: PID, TTY, TIME, and CMD. However, you can tweak these columns and show other details instead.
The -eo flag allows you to specify columns that you want to get in the output.
Rename Columns in the Output
You can also rename the column labels in the output. The -o flag will allow you to do this.
List Down Currently Running Processes
To get a list of the processes that are currently running on your system, pass the -ax flag with the ps command. The -a stands for All.
Display Processes in BSD Format
The Linux format of passing arguments with the command utilizes the - (hyphen) character. On the other hand, the BSD format doesn’t include any special characters with the argument flags.
For example, ps -A (Linux format) will display a list of all processes. The BSD equivalent of this command is:
where a stands for All and u denotes users.
Full Format Listing of Processes
To get detailed information related to the processes, pass the -ef or -eF option with the command.
The above-mentioned output contains the following information about processes.
UID: The user ID of the user responsible for the process PID: The process ID of the entry PPID: The process ID of the parent process C: CPU usage and scheduling information related to the process STIME: Time when the process was started TTY: The name of the terminal that you’re currently using TIME: Amount of CPU time used by the process CMD: The command which executed the process
Get a List of Processes Related to a User
The -u option displays a list of all the processes started by a specific user.
Show Processes Related to the Root User
To display all processes that are run by the root user, pass root with the -U and -u flag.
Get a Process PID
To get the Process ID of a particular process, use the -C flag with the command.
Replace process-name with the name of the process. The output will display the ID of the process.
List Down the Threads of a Specific Process
You might know that a process can contain multiple threads, each responsible for a specific task. To display a list of the threads of a process, use the -L flag with the ps command. Note that you will have to pass the Process ID of the process along with the command.
For example
Display Process Associated With a Particular Group
Getting a list of processes related to a certain group is easy as well. Use the -fG flag with the default command.
Alternatively, you can also pass the group ID instead of the g-roup name.
For example
Display Processes in a Tree Format
To get a hierarchical tree representation of the running processes in Linux:
The aforementioned command will display all the processes related to bash.
Monitoring Running Processes in Linux
Knowing which processes are running on your computer can prove to be helpful if you’re short on resources. You can easily kill unresponsive Linux processes that you don’t want on your system using the command-line.
For those who have low-end computers and want an operating system that offers smooth performance, many lightweight Linux distributions are available.