ps -ef Command in Linux | Explained

In Linux, ps -ef is a command that displays information about running processes on the system. The ps command stands for “process status,” and the -ef option tells the command to display information about all processes in a full format.

The ps -ef command has numerous benefits, such as process identification, system monitoring, process management, security auditing, etc. Considering the importance of the ps -ef command, this post will list a detailed explanation of the command with the help of suitable examples.

Although, the ps -ef command is applicable on all the Linux distributions. However, all the practical demonstration shown in the post is carried out on Ubuntu 22.04.

Syntax of the ps -ef Command

The basic syntax of the ps -ef command is the same as it is being written, i.e., psef. Well, let’s write it and elaborate on the entities in it.

$ ps -ef

The components of the ps -ef command are as follows:

  • ps: The command to display information about running processes on the system.
  • -e: An option to include all running processes in the output, including those not associated with the current terminal session.
  • -f: An option to display the output in a full format, which includes additional details such as process owner, parent process ID (PPID), CPU usage, and memory usage.

Examples of the ps -ef Command

Until now, you have learned the basic syntax and the working of the ps -ef command in Linux; let’s dig into some examples for a practical demonstration of the command.

Example 1: Display All Running Processes

The primary usage of the ps -ef command without examples is to get the list of all the running processes in the system. The command is as follows:

$ ps -ef

ps -ef command

The output of the ps -ef command has several columns that are explained as follows:

  • UID: The user ID (UID) who started the process.
  • PID: The process ID (PID) of the running process.
  • PPID: The parent process ID (PPID) of the running process.
  • C: The CPU utilization of the process.
  • STIME: The start time of the process.
  • TTY: The controlling terminal associated with the process.
  • TIME: The CPU time used by the process.

Example 2: Display Information About Specific Process

You have seen in the above output that all the running processes are listed. What if you want to get information about any specific process? For that, you can use the ps -ef command and pipe it with the gre command alongside its process name, as we did here to find all the information of the process named firefox:

$ ps -ef | grep firefox

ps -ef command | specific process only

Although the output is quite messy, you can find the relevant information easily, such as username process id, parent process id, and much more, as highlighted in the above image.

Example 3: Display the PIDs Only

As seen, the output of the ps -ef command is in detail. However, the users can extract specific column information about the running processes. For instance, if the user has to get the process id’s of all the running processes, then it can be done using the following command:

$ ps -ef | awk '{print $2}'

ps -ef command | PIDs Only

Only the process id column is printed on the screen.

Example 4: Display Processes of a Specific User

As from the output of the ps -ef command, the processes are associated with the username running it. For instance, the following command is used to get the processes run by a specific user, i.e., vboxuser. The username can be different in your case:

$ ps -ef | grep vboxuser

ps -ef command | specific user only

All the detailed information on the processes run by username voboxuser is displayed on the terminal. The username is highlighted in red, as seen from the output.

Example 5: Display Process Sorted By a Memory Usage

The output of the ps -ef command can be sorted by memory usage to filter the processes and exit and if the process takes much memory. For this, the ps -ef command can be used with the “–sort” flag and then the %mem filter, as shown below:

$ ps -ef --sort=-%mem

ps -ef command

The list of processes is now arranged in the ascending order of memory consumption.

Example 6: Display Process Sorted By a CPU Usage

Like memory usage, the processes can be arranged in ascending order of the CPU usage. The command written below will sort the ps -ef output as per the CPU usage:

$ ps -ef --sort=-%cpu

ps -ef command

Now, the processes are listed in ascending order of CPU usage.

Wrap Up

The ps -ef command lists all the running processes on your system. This command, UID, PID, PPID, C, STIME, TTY, and TIME of each process. The output of the ps -ef command can be molded as per the requirement of the user.
This post has listed the basic syntax of the ps -ef command and its detailed usage with the help of suitable examples. Keep supporting Linux-Genie for more Linux tips and tricks.

Print Friendly, PDF & Email