PGREP(1)
๐ซถ NAME ๐ซถ
pgrep, pkill, pidwait โ look up, signal, or wait for processes based on name and other attributes ๐
yes bestie, it's the trio. this whole page lives in the procps-ng manual, and honestly? it's giving main character energy in your process-management lineup. let's go. โจ
๐ธ SYNOPSIS ๐ธ
pgrep [option ...] pattern
pkill [option ...] pattern
pidwait [option ...] pattern
like, three little commands, one shared brain cell of options. ๐ง
๐ฆ DESCRIPTION ๐ฆ
okay so pgrep peeks through every process that's currently running and prints the process IDs of the ones that match your criteria to stdout. and here's the thing โ all the criteria have to match. every single one. no skipping.
for example:
$ pgrep -u root sshd
this will only list the processes whose name includes sshd AND that are owned by root. both. periodt. ๐
on the other hand:
$ pgrep -u root,daemon
this one lists the processes owned by root OR daemon. see how the comma switches the vibe from AND to OR? iconic honestly.
pkill sends the signal you specify (and by default that's SIGTERM) to each process instead of listing them on stdout. so instead of showing you the receipts, it acts. ๐
pidwait waits for each process instead of listing them on stdout. it's the patient one. it just sits there. vibing. waiting for your process to finish. ๐
โจ OPTIONS โจ
-signal,--signal signalโ sets which signal gets sent to every matched process. you can write it numerically or as the symbolic signal name, either is fine. but heads up: inpgreporpidwaitmode you can only use the long option, and it does literally nothing unless you pair it with--require-handlerto filter down to processes that actually have a userspace signal handler present for that particular signal. ๐-a,--list-fullโ lists the full command line and the process ID. (pgreponly, bestie.)-A,--ignore-ancestorsโ ignores all ancestors ofpgrep,pkill, orpidwait. super handy when you're elevating withsudoor similar tools and don't wanna nuke your own lineage. ๐ซถ-c,--countโ suppresses the normal output and prints a count of matching processes instead. when the count matches nothing (like, returns zero), the command returns a non-zero value. and note this: forpkillandpidwait, the count is the number of matching processes, not the ones that were successfully signaled or waited for. so don't @ me.-d,--delimiter delimiterโ sets the string used to delimit each process ID in the output. by default that's a newline. (pgreponly.)-e,--echoโ displays the name and PID of the process being killed. (pkillonly.)-f,--fullโ normally the pattern only matches against the process name. when-fis set, the full command line is used instead. ๐ฅ-F,--pidfile fileโ reads PIDs from file. this option is way more useful forpkillorpidwaitthan forpgrep. the filename-can be used to read fromSTDIN. conflicts with the--pidoption, so pick a lane.-g,--pgroup pgrp,...โ only matches processes in the process group IDs listed. process group0gets translated intopgrep's,pkill's, orpidwait's own process group. cute little self-reference.-G,--group gid,...โ only matches processes whose real group ID is listed. numerical or symbolical value, either works.-H,--require-handlerโ only matches processes with a userspace signal handler present for the signal you're about to send. so considerate of you. ๐-i,--ignore-caseโ matches processes case-insensitively. no cap.-l,--list-nameโ lists the process name as well as the process ID. (pgreponly.)-L,--logpidfileโ fails if the pidfile (see-F) is not locked.-m,--mreleaseโ after sending the signal, it invokes theprocess_mrelease()system call to immediately free the target process's memory. instant cleanup, we love to see it. โจ-n,--newestโ selects only the newest (most recently started) of the matching processes.-o,--oldestโ selects only the oldest (least recently started) of the matching processes.-O,--older secsโ selects processes older than secs.-p,--pid pid,...โ only matches processes whose process ID is listed. conflicts with the--pidfileoption.-P,--parent ppid,...โ only matches processes whose parent process ID is listed.-q,--queue valueโ sends the integer value along with the signal. this option will either usepidfd_send_signal(2)with a value applied orsigqueue(3)rather thankill(2). if the receiving process has installed a handler for this signal using theSA_SIGINFOflag tosigaction(2), then it can obtain this data via thesi_valuefield of thesiginfo_tstructure. fancy signal payload delivery, honestly iconic. ๐ฆ-Q,--shell-quoteโ outputs the command line in shell-quoted form. (pgreponly.)-r,--runstates D,R,S,Z,...โ matches only processes which match the process state. list the states you want, comma-separated.-s,--session sid,...โ only matches processes whose process session ID is listed. session ID0gets translated intopgrep's,pkill's, orpidwait's own session ID.-t,--terminal term,...โ only matches processes whose controlling terminal is listed. specify the terminal name without the/dev/prefix, bestie.-u,--euid euid,...โ only matches processes whose effective user ID is listed. numerical or symbolical value, either one.-U,--uid uid,...โ only matches processes whose real user ID is listed. numerical or symbolical value, either one.-v,--inverseโ negates the matching. usually used inpgrep's orpidwait's context. inpkill's context the short option is disabled to avoid accidental usage of the option. yeah. they took that away from you for your own safety. ๐-w,--lightweightโ shows all thread ids instead of pids inpgrep's orpidwait's context. inpkill's context this option is disabled.-x,--exactโ only matches processes whose names (or command lines if-fis specified) exactly match the pattern. no partial credit. ๐--cgroup name,...โ matches on the provided control group (cgroup) v2 name. seecgroups(7).--env name[=value],...โ matches on processes that have these environment variables. if the=valueparameter isn't defined, then only the variable name is matched.--ns pidโ matches processes that belong to the same namespaces. required to run as root to match processes from other users. see--nslistfor how to limit which namespaces get matched.--nslist name,...โ matches only the provided namespaces. available namespaces:ipc,mnt,net,pid,user,uts.--quietโ does not write anything to standard output. (pgreponly.)-V,--versionโ displays version information and exits. slay, short and sweet.-h,--helpโ displays help and exits. ๐ซถ
๐ OPERANDS ๐
- pattern โ specifies an Extended Regular Expression for matching against the process names or command lines. regex girlies rise up, this is your moment. โญ
๐ EXAMPLES ๐
Example 1: find the process ID of the named daemon:
$ pgrep -u root named
Example 2: make syslog reread its configuration file:
$ pkill -HUP syslogd
Example 3: give detailed information on all bash processes:
$ ps -fp $(pgrep -d, -x bash)
Example 4: make all chrome processes run nicer:
$ renice +4 $(pgrep chrome)
Example 5: wait for a process with a known PID to finish:
$ echo ${PID} | pidwait -F -
look at that pipeline in example 5. it's giving elegance. ๐ฆ
๐ EXIT STATUS ๐
0โ one or more processes matched the criteria. forpkillandpidwait, one or more processes must also have been successfully signalled or waited for.1โ no processes matched, or none of them could be signalled.2โ syntax error in the command line. oops.3โ fatal error: out of memory, etc. ๐ญ
โญ NOTES โญ
the process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. use the -f option to match against the complete command line, /proc/pid/cmdline. also, threads may not have the same process name as the parent process, but they will have the same command line. the more you know. ๐ซ
the running pgrep, pkill, or pidwait process will never report itself as a match. self-awareness queen.
the -O --older option will silently fail if /proc is mounted with the subset=pid option. silent failure is the worst kind of failure, ngl. ๐
pkill will attempt to use pidfd_send_signal(2) instead of kill(2) or sigqueue(3) to send a signal to the target process if it is able to get the process file descriptor. glow up.
๐ BUGS ๐
the options -n and -o and -v can not be combined. "let me know if you need to do this," the author says, and honestly? king behaviour.
if processes start in the same clock tick (usually but not always a 100th of a second), the options -n and -o will not be able to distinguish which process started in the same clock tick and may give erroneous results. so be careful out there. ๐ญ
defunct processes are reported. yes, the zombie ones. they're in the list. ๐ง
pidwait requires the pidfd_open(2) system call, which first appeared in Linux 5.3. if you're on something older, sorry bestie. ๐
๐ฅ SEE ALSO ๐ฅ
killall(1), kill(1), ps(1), skill(1), kill(2), sigaction(2), pidfd_open(2), pidfd_send_signal(2), sigqueue(3), cgroups(7), regex(7), signal(7)
the whole friend group. go say hi. ๐ซถ
๐ REPORTING BUGS ๐
please send bug reports to procps@freelists.org. they wanna hear from you, fr fr. โ๏ธ
okay that's the whole page, bestie!! ๐
โจ this one's from procps-ng, dated 2025-12-29, and yes it's the PGREP(1) manual page you just read the entire vibe of. go forth and pgrep responsibly. no cap. ๐๐ฆ๐ธ๐
๐ฆ where this page comes from
- arch rolling: procps-ng 4.0.7-1 ยท GPL AND LGPL
- nixpkgs unstable: procps 4.0.7
- ubuntu stonking: procps 2:4.0.6-3ubuntu1 ยท LGPL-2.1-or-later
- Copyright (c) 2004-2025 Craig Small <csmall@dropbear.xyz>
- Copyright (c) 2013-2024 Jim Warner <james.warner@comcast.net>
- Copyright (c) 2011-2012 Sami Kerola <kerolasa@iki.fi>
- Copyright (c) 2002-2004 Albert Cahalan
- Copyright (c) 2000 Kjetil Torgrim Homme
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms