pgrep - another little known FreeBSD command

Have you ever wanted to perform an action on a large set of processes which are forked from one another (or started from the same binary in some other way) but were stopped by the need to use awk or something else to parse the PIDs from the output of ps or a similar utility? Pgrep allows you to do just that!

The pgrep utility is actually not a program developed specifically for FreeBSD - its history section says:

"The pkill and pgrep utilities first appeared in NetBSD 1.6.  They are  modelled after utilities of the same name that appeared in Sun Solaris 7. They made their first appearance in FreeBSD 5.3."

... but I have a feeling it's still one of the underused utilities. Again, it is best to explain what it does with an example:

renice 10 `pgrep make`

That command will renice all "make" processes, such as those started by the buildworld process (the point being that all the compilers and other utility processes will inherit this niceness value).

This is probably the simplest usable example of using pgrep, but the utility supports a large number of parameters with which various sets of processes can be selected, such as those belonging to a certain user, or having a certain parent process, or from a certain jail, or even inverting the query (i.e. querying processes NOT from a certain set). The name argument to pgrep is actually a regular expression pattern, which can be further used to find very specific processes.

It's one of those utilities which can save a lot of time if used properly.

#1 pgrep++ ... let's add more p... tools

Added on 2013-10-05T04:29 by zfsrox
    I agree .. I alike a lot of the solaris process tools too ... maybe *BSD's can add some ofthose where appropriate. pldd is really nice ..:)
    proc, pflags, pcred, pmap, pldd, psig, pstack, pfiles, pwdx, pstop, prun, pwait, ptree, ptime ...

#2 Re: pgrep++ ... let's add more p... tools

Added on 2014-04-06T19:03 by scott

tuning linux process scheduling with nice and renice command with examples is explained well at

Comments !