In multiprocessing operating systems like Linux, processes form an integral part of the system workflow. Sometimes, users need to list the running processes on a system for monitoring purposes. In such situations, Linux command-line utilities can be helpful.

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.

Related: What is a Process in Linux?

How to Use the ps Command in Linux

The basic syntax of the ps command is:

        ps [options]
    

Running the ps command without any arguments produces the following output:

        ps
    
ps command in linux

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.

        ps -A
ps -e
all processes in linux

View Processes Associated With the Terminal

The -T flag will display the list of all the processes related to the terminal.

        ps -T
    

You will see an output that looks something like this.

terminal related process in linux

Display Processes Not Associated With the Terminal

The -a flag will list down processes that aren't associated with the current terminal.

        ps -a
    

The screen will display an output.

processes in linux

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.

        ps -T -N
ps -T --deselect
ps command list processes

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.

        ps -eo pid, uname, pcpu, stime, pri, f
    
custom output in ps command

Rename Columns in the Output

You can also rename the column labels in the output. The -o flag will allow you to do this.

        ps -e -o pid=Process_ID, uid=User_ID, com=COMMAND
    

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.

        ps -ax
    
display all executing processes in linux

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:

        ps au
    

where a stands for All and u denotes users.

list down processes in bsd format

Full Format Listing of Processes

To get detailed information related to the processes, pass the -ef or -eF option with the command.

        ps -ef
ps -eF
ps command in linux

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

The -u option displays a list of all the processes started by a specific user.

        ps -u username
    
user specific process

To display all processes that are run by the root user, pass root with the -U and -u flag.

        ps -U root -u root
    
root related processes

Get a Process PID

To get the Process ID of a particular process, use the -C flag with the command.

        ps -C process-name
    

Replace process-name with the name of the process. The output will display the ID of the process.

        ps -C bash
    
bash related processes

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.

        ps -L pid
    

For example

        ps -L 1250
    
get a specific pid

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.

        ps -fG groupname
    

Alternatively, you can also pass the group ID instead of the g-roup name.

        ps -fG groupid
    

For example

        ps -fG sudoers
ps -fg 1000
group related processes

Display Processes in a Tree Format

To get a hierarchical tree representation of the running processes in Linux:

        ps -f --forest -C bash
    

The aforementioned command will display all the processes related to bash.

tree view in ps

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.