- published: 17 Dec 2012
- views: 441
pgrep is a command-line utility initially written for use with the Solaris 7 operating system. It has since been reimplemented for Linux and the 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.
The default behaviour of pgrep (returning the process identifier of the named tasks) simplifies an otherwise complex task and is invoked with:
<source lang="bash"> pgrep 'bash' </source>
Which is roughly equivalent to:
<source lang="bash"> ps ax | awk '/[p]rocessname/ {print $1}'
</source>
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):
<source lang="bash"> pgrep -l -G alice </source>
Written By John Siegler John Loeffler
Lead Vocals: Johto
Background Vocals: Johto
P-O-K-É-M-O-N!
P-O-K-É-M-O-N!
P-O-K-É-M-O-N!
P-O-K-É-M-O-N!
Sunflora, Igglybuff, Piloswine, Slugma, Crobat, Politoed, Noctowl, Houndour,
Heracross, Natu, Tyrogue, Ariados, Lugia, Steelix, Phanpy , Ampharos
Sudowoodo, Corsola, Teddiursa, Sneasel, Forretress, Mantine, Pichu, Larvitar,
HootHoot, Miltank, Totodile, Gligar, Lanturn, Skarmory, Spinarak, Tyranitar
Chikorita, Dunsparce, Aipom, Pupitar, Porygon2, Cyndaquil, Elekid, Raikou,
Wobbuffet, Typhlosion, Granbull, Stantler, Espeon, Ledyba, Togepi
I turn to you, whenever I need you
You've got the power to protect us all
One thing is true
Your kind of magic's
At the tip of my fingers
Whenever I call
Qwilfish, Ho-oh, Azumarill, Croconaw, Snubbull, Ursaring, Yanma, Smoochum,
Slowking, Blissey, Scizor, Donphan, Houndoom, Octillery, Wooper, Mareep,
Hitmontop, Marill, Umbreon, Bayleaf
Sunkern, Ledian, Girafarig, Murkrow, Remoraid, Jumpluff, Quilava, Smeargle,
Swinub, Magcargo Furret, Bellossom, Flaaffy, Entei, Meganium, Magby
Xatu, Misdreavus, Togetic, Shuckle, Quagsire, Pineco, ChinChou, Feraligatr,
Hoppip, Kingdra, Unown, Cleffa, Suicune, Delibird, Sentret, Skiploom