On Unix-like operating systems, the pgrep command searches for processes currently running on the system, based on a complete or partial process name, or other specified attributes.
The pkill command sends a signal to one or more processes, using the same flexible selection methods as pgrep.
This page covers the GNU/Linux versions of pgrep and pkill.
Description
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. All the criteria have to match. For example,
- Description
- Syntax
- Examples
- Related commands
- Linux commands help
pgrep -u root ssh
…will only list the processes that are called sshd and are owned by root. On the other hand,
pgrep -u root,daemon
…will list the processes owned by root OR daemon.
pkill sends the specified signal (by default SIGTERM) to each process instead of listing them on standard output.
Syntax
pgrep [options] pattern
pkill [options] pattern
Options
Examples
pgrep -u root named
Find the process ID of the named (name daemon) process.
pkill -HUP syslogd
Send the HUP signal to syslogd, which forces it to re-read its configuration file.
renice +4 $(pgrep firefox)
Make all firefox processes run nicer by a value of 4. This command illustrates the way pgrep’s output can be passed to other utilities as input. In this case, the command pgrep firefox is passed as an argument to renice because it is enclosed in $( ).
Related commands
ps — Report the status of a process or processes.killall — Kill processes by name.kill — Send a signal to a process, affecting its behavior or killing it.