Pgrep

Command-line utility that searches and displays named processes


title: "Pgrep" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["unix-process--and-task-management-related-software"] description: "Command-line utility that searches and displays named processes" topic_path: "technology/operating-systems" source: "https://en.wikipedia.org/wiki/Pgrep" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0

::summary Command-line utility that searches and displays named processes ::

::data[format=table title="Infobox software"]

FieldValue
namepgrep
authorMike Shapiro
operating systemUnix and Unix-like
genreCommand
::

| name = pgrep | logo = | screenshot = | screenshot size = | caption = | author = Mike Shapiro | developer = | released = | latest release version = | latest release date = | operating system = Unix and Unix-like | genre = Command | license = | website = **pgrep** is a command-line utility initially written for use with the Solaris 7 operating system by Mike Shapiro. It has since been available in illumos and reimplemented for the Linux and BSDs (DragonFly BSD, FreeBSD, NetBSD, and OpenBSD). It searches for all the named processes that can be specified as extended regular expression patterns, and—by default—returns their process ID. Alternatives include [pidof](pidof) (finds process ID given a program name) and [ps](ps-unix).

Example usage

The default behaviour of pgrep (returning the process identifier of the named tasks) simplifies an otherwise complex task and is invoked with: ::code[lang=bash] $ pgrep 'bash' ::

Which is roughly equivalent to: ::code[lang=bash] $ ps ax | awk '{sub(/.*//, "", $5)} $5 ~ /bash/ {print $1}' ::

Additional functionality of pgrep is listing the process name as well as the PID (-l Lists the process name as well as the process ID) of all processes belonging to the group alice (-G Only match processes whose real group ID is listed. Either the numerical or symbolical value may be used): ::code[lang=bash] $ pgrep -l -G alice ::

showing all processes that do not belong to the user [root](superuser) (-u euid Only match processes whose effective user ID is listed. Either the numerical or symbolical value may be used) by inverting the matching (-v Negates the matching): ::code[lang=bash] $ pgrep -v -u root ::

and only matching the most recently started process (-n Select only the newest (most recently started) of the matching processes): ::code[lang=bash] $ pgrep -n # The most recent process started $ pgrep -n -u alice emacs # The most recent emacs process started by user alice ::

References

::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::

unix-process--and-task-management-related-software