Check Running Process in Linux Command | More than One Way to do it

Check Running Process in Linux Command

In Linux, running processes are one of the most important aspects of system management. As an administrator, you need to have a clear understanding of the processes that are running on your system to ensure that the system is running smoothly and efficiently. In this article, we will have a thorough understanding of different check running process in linux command.

 

In Linux, processes are the programs or instructions that are running on the system. Each process is allocated a unique Process ID (PID) that helps to identify it. The kernel of the Linux operating system manages and controls these processes. It is responsible for scheduling processes, allocating resources and maintaining their state.

 

ps Command in Linux 

 

ps Command in Linux 
ps Command in Linux

 

The ps command is the most commonly used command to check running processes on Linux. Whether you are a newbie or an experienced Linux user, it is crucial to know how to use the ps command. This tool provides detailed information on the processes running on your system, including their parent processes, PID, CPU usage, and other relevant details. In this guide, we will provide you with a comprehensive overview of how to use the ps command to check running processes on Linux.

 

The basic syntax of the ps command is as follows:

 

  • $ ps [options]

 

The ps command can be used with various options to display specific information about running processes. For instance, the “-a” option displays the processes that are running on the system, while the “-u” option displays the user processes information. The following is a list of some popular options that are used with the ps command:

 

-a: This option displays all running processes on the system.
-u: This option displays the user and CPU time information associated with each process.
-c: This option displays the command name, along with the process details.
-x: This option displays the processes that are not associated with any terminal.

 

To display a full list of available options, you can use the following command:

 

  • $ ps –help

 

One of the most powerful features of the ps command is that it can display information about specific processes on the system. For instance, if you are interested in knowing the CPU usage of your web server, you can run the following command:

 

  • $ ps aux | grep apache

 

This command will display all the processes that have the word “apache” in their name. You can then use the information provided to monitor the CPU usage of your web server.

 

Another useful way to use the ps command is to sort processes based on specific criteria. For example, you may wish to sort processes by their CPU usage or memory usage. To do this, you can use the “-o” option along with a specific format specifier. For instance, the following command will display the processes sorted in descending order based on their memory usage:

 

  • $ ps aux –sort=-rss

 

Commonly used syntax options for ps command 

 

-ef: Displays all processes (except the ones running through SSH or in the background) in full detail.

 

-a: Displays all processes for all users.

 

-u username: Displays all processes for a specific user.

 

-aux: Displays all processes (including the ones running through SSH or in the background) in full detail for all users.

 

-ajx : Displays all processes (including the ones running through SSH or in the background) in a tree-like format.

 

-ely: Displays all processes (including the ones running through SSH or in the background) in a long format for all users.

 

-h: Hides the header row.

 

-N: Hides non-TTY processes.

 

–sort column: Sorts the output by the specified column (CPU, pid, etc.).

 

pgrep Command 

 

pgrep Command 
pgrep Command

 

The pgrep command searches for specific processes by name and returns a list of all matching processes. This can be incredibly useful for monitoring the status of critical applications and services, identifying rogue processes that may be consuming too many system resources, and troubleshooting issues in real-time.

To use the pgrep command, simply open up your terminal or shell and enter the following command:

  • pgrep [process_name]

Replace [process_name] with the name of the process you wish to search for. For example, if you wanted to check whether the Apache HTTP server was running, you would enter:

pgrep httpd

The pgrep command will return a list of all running Apache processes on your system. If no processes are found, the command will return no output.

Additionally, you can use pgrep with other commands to perform more complex operations, such as filtering results or killing specific processes. For example, you can easily check for a specific user’s running processes by using the following command:

  • pgrep -u [username]

Replace [username] with the name of the user you wish to search for. This command will return a list of all processes running on the system that have been started by the specified user.

If you need to kill a specific process, you can use the pkill command along with the pgrep command. For example, to kill all instances of the Apache HTTP server running on your system, you would enter:

  • pkill httpd

This will send a signal to all Apache processes on your system, causing them to terminate immediately.

 

 

pstree Command 

The pstree command is a useful tool for checking running processes on Linux systems. This command provides information on the processes running on the system and their parent-child relationships. By default, the pstree command displays the processes in a tree-like format, making it easy to understand the hierarchy and dependencies between them.

 

The syntax for using the pstree command is relatively simple. The basic syntax for this command is as follows:

 

  • pstree [OPTIONS] [PID/USERNAME]

 

The OPTIONS available for the pstree command vary depending on the version of the Linux distribution being used. However, some common options include:

 

  • * -a: This option displays the command line arguments for each process.
  • * -c: This option displays the process names without truncating them.
  • * -h: This option shows the process hierarchy more clearly by highlighting the selected process in the tree.
  • * -p: This option includes the process ID of each process in the output.

 

The PID/USERNAME argument specifies the process ID or username of the processes to display. If this argument is not specified, pstree will display the tree for all processes running on the system.

 

When using the PID argument, you can specify multiple process IDs separated by a space. This allows you to view the relationship between selected processes.

 

Here are some examples of how to use the pstree command:

 

To display the tree for all processes running on the system:

 

pstree

 

To display the tree for a specific process, identified by its process ID:

 

  • pstree 1234

 

To display the tree for processes belonging to a specific user:

 

  • pstree username

 

To display the tree for multiple processes, identified by their process IDs:

 

  • pstree 1234 5678 91011

Conclusion

In conclusion, checking running processes in Linux is a critical task for system administrators. By using the appropriate commands and tools, you can effectively manage and monitor your system processes, ensuring that your system runs efficiently and securely.

 

 

  • Share:
Send a Message