Check Running Processes in Linux

January 14, 2025 / General Discussion

Monitoring the processes running on a Linux system is an essential task for system administrators and users who want to manage system resources effectively. This guide will walk you through various methods to check running processes in Linux in a human-readable way.

1. Using the ps Command

The ps command displays information about active processes. It’s one of the simplest ways to view running processes.

Basic Usage:

ps

This command shows processes related to the current terminal session.

Common Options:

  • ps -e: Displays all processes.
  • ps -f: Shows full-format listing, including additional details like the user and command.
  • ps aux: Provides a comprehensive view of all processes along with their CPU and memory usage.

Example:

ps aux | less

This command lists all processes and pipes the output into less for easier navigation.

2. Using the top Command

The top command is an interactive utility that provides a dynamic, real-time view of system processes.

Run the Command:

top

Key columns include:

  • PID: Process ID
  • USER: User running the process
  • %CPU: CPU usage
  • %MEM: Memory usage

Interactive Controls:

  • Press q to quit.
  • Use h for help within the top interface.

3. Using the htop Command

htop is an enhanced alternative to top with a more user-friendly interface. It provides color-coded information and easier navigation.

Install htop (if not already installed):

sudo apt install htop # For Debian/Ubuntu
sudo yum install htop # For CentOS/RHEL

Run the Command:

htop

4. Using the pidof Command

The pidof command is useful for finding the PID of a specific process.

Usage:

pidof <process_name>

For example, to find the PID of the nginx service:

pidof nginx

5. Using the pgrep Command

The pgrep command searches for processes based on name and other attributes.

Basic Usage:

pgrep <process_name>

Example:

pgrep ssh

This will list the PIDs of all processes related to ssh.

6. Using the jobs Command

The the jobs command displays processes started by the current shell.

Run the Command:

jobs

This is particularly useful for managing background and stopped jobs in the terminal.

7. Using the /proc Filesystem

Linux maintains information about processes in the /proc directory. Each running process has a corresponding directory under /proc with its PID as the name.

Example:

To view the status of a process with PID 1234:

cat /proc/1234/status

8. Using the systemctl Command

For systems using systemd, the systemctl command helps monitor service-related processes.

List Active Services:

systemctl list-units –type=service

Check the Status of a Specific Service:

systemctl status apache2

9. Using the netstat Command

To view processes related to network activity, the netstat command can be useful.

Example:

netstat -tulnp

10. Combining Commands for Detailed Output

You can combine commands with grep to filter specific results.

Example:

To find all processes running under a specific user:
ps -u <username>

To filter for a specific process:
ps aux | grep <process_name>

These commands provide versatile ways to monitor and manage processes on a Linux system. By mastering these tools, you can efficiently track system performance, diagnose issues, and optimize resource usage.

Learn More: How to Check the Size of a Directory in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *