search

To find processes by name in Linux, the most common method is to use the ps command combined with grep. First execute ps aux to list all processes, and then filter the target name through grep. For example, ps aux | grep nginx can view nginx process information. The first line shows the details of running processes, and the second behavior grep's own process needs to be ignored; if you are not sure about the name case, you can use ps aux | grep -i nginx to ignore case queries. If you only need to check whether the process exists and get the PID, it is recommended to use pgrep nginx, which is simple and only the process ID. Adding the -l parameter can display the name pgrep -l nginx at the same time. -i also supports ignoring upper and lower case. For exact matches, try pidof nginx, but the tool is less flexible and the system may not be preinstalled. Each of the three methods has its advantages. Use ps grep for details, use pgrep for quick query, and use pidof for exact match.

How to find a process by name on Linux

To find a process by name on Linux, the most common and effective method is using the ps command combined with grep . This lets you quickly filter running processes based on their names or parts of them.

Use ps and grep Together

This is the go-to method for most users. The basic idea is to list all running processes and then search for the one you're interested in.

Here's how you do it:

 ps aux | grep process_name
  • ps aux lists all running processes.
  • grep process_name filters that list to show only lines containing the name you're looking for.

For example, if you're trying to find if nginx is running:

 ps aux | grep nginx

You'll see output like this:

 root 1234 0.0 0.1 12345 6789 ? Ss 10:00 0:00 /usr/sbin/nginx
user 5678 0.0 0.0 11223 4567 pts/0 S 10:05 0:00 grep --color=auto nginx

The second line is the grep command itself — just ignore that. The first line shows nginx is actually running.

One thing to note: case matters. If you're not sure about the exact name or want to ignore case, add -i to grep :

 ps aux | grep -i nginx

Try pgrep for a Simpler Output

If you don't need full details but just want to check if a process is running, pgrep is your friend. It prints only the process IDs (PIDs), which can be useful if you plan to use the PID in another command later.

Usage:

 pgrep process_name

Example:

 pgrep nginx

If nginx is running, this will return something like:

 1234

That's the PID. If nothing shows up, the process isn't running.

  • You can also use -l to show the process name along with the PID:

     pgrep -l nginx
  • And again, -i makes the match case-insensitive:

     pgrep -li nginx

Consider pidof for Exact Matches

Another quick tool is pidof , which finds the PID of a running process by its exact execute name.

Basic usage:

 pidof process_name

Example:

 pidof nginx

This returns the same as pgrep , but it's stricter — it matches only the exact execute name.

  • Some systems might not have pidof installed by default.
  • It doesn't support case-insensitive matching like pgrep does.

So while it's fast and clean, it's a bit less flexible than pgrep .


All three methods work well depending on what you need. For detailed info, stick with ps grep . For quick looksups, pgrep is more convenient. And if you know the exact name and want speed, pidof gets the job done.

Basically that's it.

The above is the detailed content of How to find a process by name on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to use the iostat commandHow to use the iostat commandSep 07, 2025 am 01:37 AM

iostat is a tool used in Linux systems to monitor CPU usage and disk I/O. 1. After installation, you can directly run iostat to view overall statistics; 2. Use iostat25 to monitor in real time, output every 2 seconds 5 times; 3. Key indicators including %iowait high may indicate slow disk, high tps and kB_read/s/kB_wrtn/s may indicate excessive disk load; 4. When troubleshooting problems, it is recommended to find specific processes in combination with iotop or pidstat and observe trends many times; 5. Commonly used parameters such as iostat-x display detailed information, iostat-xmt1 view response time, and iostatsda2 monitor specific devices. Master these methods

How to verify backupsHow to verify backupsSep 07, 2025 am 01:10 AM

Verifying backups requires regular checks on validity, not just storage. 1. Check whether the backup is complete, confirm that the key files exist, view the logs, and use verification tools to ensure consistency; 2. In fact, simulate the recovery process, execute at least once a quarter, and verify the accessibility and integrity of the data; 3. Set up monitoring and reminder mechanisms, such as calendar reminders, health status monitoring tools, script email notifications, to ensure that the backup is successful and that someone knows the status.

How to use `tar` for backupsHow to use `tar` for backupsSep 06, 2025 am 03:08 AM

Tobackupfileswithtar,usebasiccommandsforbundlingfiles,addcompressionforspacesavings,performincrementalbackupstosaveonlychanges,andautomaterotationsforregularmaintenance.Startbycreatingabasictararchivewithtar-cvfbackup.tar/path/to/folderforaquicksnaps

How to load a kernel moduleHow to load a kernel moduleSep 06, 2025 am 02:25 AM

The key to loading a kernel module is to clarify the module status and loading method. 1. First use lsmod to check whether the module has been loaded to avoid repeated operations; 2. It is recommended to use modprobe to automatically handle dependencies, such as sudomodprobevboxdrv; 3. In special cases, insmod can be used to manually load the .ko file of the specified path, but pay attention to the correctness of the path; 4. If you want to automatically load on the computer, you can add the module name in the /etc/modules-load.d/ configuration file to achieve long-term effectiveness. During operation, you need to ensure sufficient permissions and confirm that the module exists.

How to install a package using aptHow to install a package using aptSep 05, 2025 am 12:01 AM

The key to installing a software package using apt is to master five core steps. 1. Update the software source list: execute sudoaptupdate to ensure the latest version information is obtained; 2. Search the software package: use the apt-cachesearch package name to find the required software package; 3. Install the specified software package: run the sudoaptinstall package name for installation. When the version is uncertain, you can use the apt-cacheshow package name to view details; 4. Uninstall the software package: delete the software through the sudoaptremove package name. If you need to delete the configuration file, use the sudoaptpurge package name; 5. Clean up the residual dependencies: execute sudoaptautoremove to keep the system clean. Skip update source

How to schedule a task using crontabHow to schedule a task using crontabSep 04, 2025 am 04:52 AM

To use crontab to execute tasks regularly, first edit the crontab file, enter the command crontab-e and add a task entry formatted as "Time-sharing Day, Moon, Week, and Day Command". Secondly, use crontab-l to view existing tasks, or edit and delete tasks again; finally pay attention to issues such as environment variables, output redirection, script permissions and test time settings to ensure that the task runs normally.

How to export logs from journalctlHow to export logs from journalctlSep 04, 2025 am 12:56 AM

To export logs from journalctl, you can use different formats and filter conditions to get the required information. 1. Use journalctl>all_logs.txt to export all logs as text; 2. Use parameters such as -b (last startup), -unginx (specified service) to limit the scope; 3. Use options such as --output=json, --output=json-pretty or --output=cat to export in a structured format; 4. Use --since and --until to specify the time window; 5. Combine multiple parameters to accurately extract data, such as journalctl-unginx--since"1h

How to process in Linux Linux FIFO scheduling policyHow to process in Linux Linux FIFO scheduling policySep 03, 2025 pm 12:39 PM

To make Linux processes run in real-time FIFO scheduling, you need to use the chrt command or sched_setscheduler system call to set the scheduling policy and priority, such as sudochrt-f99./app or configure SCHED_FIFO and priority parameters in the C program, and ensure that the process has CAP_SYS_NICE capability or root permissions, and configure rtprio and memlock restrictions through limits.conf to ensure real-timeness and avoid priority reversal. You need to use a mutex that supports priority inheritance.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!