Skip to main content

Command Palette

Search for a command to run...

How to Find Process in Linux

Published
6 min readView as Markdown

Finding processes in Linux is a basic yet essential skill for anyone working with this operating system. Whether you want to check if a program is running, monitor system performance, or troubleshoot issues, knowing how to find processes quickly can save you a lot of time. In this article, I’ll guide you through several easy methods to locate processes on your Linux system.

You don’t need to be a Linux expert to follow along. I’ll explain each command clearly and show you examples so you can try them yourself. By the end, you’ll feel confident using these tools to find any process you need.

Understanding Linux Processes

Before diving into commands, it helps to understand what a process is. In Linux, a process is simply a running instance of a program. Each process has a unique Process ID (PID) and other details like the user running it, CPU usage, and memory consumption.

Processes can be system services, user applications, or background tasks. Finding a process means identifying it by name, PID, or other attributes. This knowledge is useful for managing system resources or killing unresponsive programs.

Using the ps Command to Find Processes

The ps command is one of the most common ways to view running processes in Linux. It stands for “process status” and displays information about active processes.

Here’s how you can use it:

  • ps alone shows processes running in the current shell.
  • ps -e or ps -A lists all processes on the system.
  • ps -ef gives a full-format listing with detailed info.
  • ps aux shows all processes with user-oriented details.

For example, to find a process by name, you can combine ps with grep:

ps -ef | grep firefox

This command lists all processes and filters those containing “firefox.” It shows the PID, user, CPU usage, and more.

Tips for Using ps

  • Use ps -ef for a detailed view.
  • Combine with grep to search by process name.
  • Use ps aux for a user-friendly format.
  • Remember that ps shows a snapshot, not a live list.

Finding Processes with pidof

If you want to find the PID of a specific program quickly, pidof is a handy command. It returns the process ID(s) of a running program by name.

For example:

pidof sshd

This will output the PID(s) of the SSH daemon if it’s running.

Why Use pidof?

  • It’s simple and fast.
  • Returns only PIDs, no extra info.
  • Useful for scripts or quick checks.

Monitoring Processes with top and htop

Sometimes you want to find processes and monitor their resource usage in real-time. That’s where top and htop come in.

Using top

top is pre-installed on most Linux systems. It shows a live list of processes sorted by CPU usage by default.

  • Run top in the terminal.
  • Press / and type a process name to search.
  • Use k to kill a process by PID.
  • Press q to quit.

Using htop

htop is an enhanced version of top with a better interface.

  • It shows color-coded CPU, memory bars.
  • Allows mouse interaction.
  • Supports filtering and sorting.
  • Install it via your package manager (sudo apt install htop).

Both tools help you find processes and understand their impact on your system.

Searching Processes by Name with pgrep

pgrep is designed to find processes by name or other attributes. It outputs the PIDs matching your criteria.

For example:

pgrep -l chrome

This lists all processes with “chrome” in their name along with their PIDs.

Useful pgrep Options

  • -u username to find processes by a specific user.
  • -f to match against the full command line.
  • -d ',' to separate multiple PIDs with commas.

pgrep is great for scripting and automation.

Using pidstat for Detailed Process Stats

If you want detailed statistics about processes, pidstat is a powerful tool. It reports CPU, memory, and I/O usage per process.

Example:

pidstat -p 1234 1

This monitors process with PID 1234 every second.

When to Use pidstat

  • For performance monitoring.
  • To analyze resource usage over time.
  • When troubleshooting slow or stuck processes.

Finding Processes by User

Sometimes you want to find all processes running under a specific user. You can do this with ps or pgrep.

Using ps:

ps -u username

This lists all processes owned by “username.”

Using pgrep:

pgrep -u username

This returns PIDs of all processes for that user.

Using lsof to Find Processes Using Files

lsof lists open files and the processes using them. It’s useful if you want to find which process is using a specific file or port.

Example:

lsof /var/log/syslog

This shows processes accessing the syslog file.

To find processes listening on a port:

lsof -i :80

This lists processes using port 80.

Killing a Process After Finding It

Once you find a process, you might want to stop it. Use the kill command with the PID:

kill 1234

If the process doesn’t stop, use a stronger signal:

kill -9 1234

Be careful with kill -9 as it forces termination without cleanup.

Summary Table of Commands to Find Processes

CommandDescriptionExample
ps -efList all processes with details`ps -efgrep nginx`
pidofGet PID of a programpidof sshd
topReal-time process monitoringtop
htopInteractive process viewerhtop
pgrepFind PIDs by name or userpgrep -u root
pidstatDetailed process statspidstat -p 1234 1
lsofList processes using files/portslsof -i :22
killTerminate a process by PIDkill 5678

Conclusion

Finding processes in Linux is easier than you might think. Whether you prefer simple commands like ps and pidof or interactive tools like top and htop, there’s a method for every need. You can search by process name, user, or even by the files they use.

By mastering these commands, you’ll be able to monitor your system effectively, troubleshoot problems, and manage resources better. Try these commands yourself and see how quickly you can find any process running on your Linux machine.

FAQs

How do I find the PID of a process by name?

Use pidof processname or pgrep processname to get the PID(s) of a running process by its name.

Can I find processes running under a specific user?

Yes, use ps -u username or pgrep -u username to list processes owned by a particular user.

What is the difference between top and htop?

top is a basic real-time process viewer, while htop offers a more user-friendly, interactive interface with color and mouse support.

How do I find which process is using a specific port?

Use lsof -i :portnumber to list processes listening on or using that port.

How can I kill a process after finding its PID?

Run kill PID to terminate a process. Use kill -9 PID for a forceful kill if needed.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts