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: in pgrep or pidwait mode you can only use the long option, and it does literally nothing unless you pair it with --require-handler to 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. (pgrep only, bestie.)
  • -A, --ignore-ancestors โ€” ignores all ancestors of pgrep, pkill, or pidwait. super handy when you're elevating with sudo or 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: for pkill and pidwait, 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. (pgrep only.)
  • -e, --echo โ€” displays the name and PID of the process being killed. (pkill only.)
  • -f, --full โ€” normally the pattern only matches against the process name. when -f is set, the full command line is used instead. ๐Ÿ”ฅ
  • -F, --pidfile file โ€” reads PIDs from file. this option is way more useful for pkill or pidwait than for pgrep. the filename - can be used to read from STDIN. conflicts with the --pid option, so pick a lane.
  • -g, --pgroup pgrp,... โ€” only matches processes in the process group IDs listed. process group 0 gets translated into pgrep's, pkill's, or pidwait'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. (pgrep only.)
  • -L, --logpidfile โ€” fails if the pidfile (see -F) is not locked.
  • -m, --mrelease โ€” after sending the signal, it invokes the process_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 --pidfile option.
  • -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 use pidfd_send_signal(2) with a value applied or sigqueue(3) rather than kill(2). if the receiving process has installed a handler for this signal using the SA_SIGINFO flag to sigaction(2), then it can obtain this data via the si_value field of the siginfo_t structure. fancy signal payload delivery, honestly iconic. ๐Ÿ“ฆ
  • -Q, --shell-quote โ€” outputs the command line in shell-quoted form. (pgrep only.)
  • -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 ID 0 gets translated into pgrep's, pkill's, or pidwait'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 in pgrep's or pidwait's context. in pkill'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 in pgrep's or pidwait's context. in pkill's context this option is disabled.
  • -x, --exact โ€” only matches processes whose names (or command lines if -f is specified) exactly match the pattern. no partial credit. ๐Ÿ’…
  • --cgroup name,... โ€” matches on the provided control group (cgroup) v2 name. see cgroups(7).
  • --env name[=value],... โ€” matches on processes that have these environment variables. if the =value parameter 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 --nslist for 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. (pgrep only.)
  • -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. for pkill and pidwait, 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