Pgrep

pgrep
Original authorMike Shapiro
Operating systemUnix and Unix-like
TypeCommand

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 (finds process ID given a program name) and ps.

Example usage

The default behaviour of pgrep (returning the process identifier of the named tasks) simplifies an otherwise complex task and is invoked with:

$ pgrep 'bash'

Which is roughly equivalent to:

$ 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):

$ pgrep -l -G alice

showing all processes that do not belong to the user root (-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):

$ pgrep -v -u root

and only matching the most recently started process (-n Select only the newest (most recently started) of the matching processes):

$ pgrep -n                # The most recent process started
$ pgrep -n -u alice emacs # The most recent `emacs` process started by user `alice`

See also

  • List of Unix commands
  • pidof — find the process ID of running 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

References

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.