pgrep

From Wikipedia, the free encyclopedia

pgrep is a command line utility initially written for use with the Solaris 7 operating system. It has since been reimplemented for Linux and OpenBSD. It searches for all the named processes, that can be specified as extended regular expression patterns, and, by default, returns their ID. Alternatives include pidof and ps.

[edit] Example usage

pgrep's default behaviour (returning the process id(s) of the named task(s)) is invoked by typing:

pgrep taskname

This is roughly equivalent to the following command:

ps ax | grep taskname | grep -v grep | awk '{print $1}'

Hence, pgrep simplifies an otherwise complex task. pgrep also has additional functionality, e.g.:

  • Show all processes (in long form, ID and name) belonging to the other group:
pgrep -l -G other
  • Show all process not belonging to root user:
pgrep -v -u root

[edit] See also

  • List of Unix programs
  • pkill – signal processes based on name and other attributes
  • ps – display the currently running processes
  • grep – search for lines of text that match one or many regular expressions

[edit] References