The pgrep command is a tool for looking through currently running processes based on a number of different attributes and providing the process IDs (PIDs), but it does a lot of other things as well. The available options won't necessarily be the same as you move from one system to another, but you're sure to discover some pgrep commands that will prove very useful when you're busy looking into what's running on your systems.\nThe most basic pgrep command will display the PIDs for whatever command you might be inquiring about. For example, if you want a list of all of the Apache daemons running on a web server, the pgrep httpd command does that easily.\n$ pgrep httpd\n2854\n10596\n10597\n10598\n10599\n10600\n10601\n10602\n10603\n15142\n17559\n\nIf you have the -c (count) option available, you can count the processes rather than showing their PIDs.\n$ pgrep -c httpd\n11\n\nIf you don't have the -c option available, you can do this instead:\n$ pgrep -c httpd | wc -l\n11\n\nWhen you want to list PIDs for processes being run by some particular user, try the -u option as shown in this example. This allows you to search by username rather than process names.\n$ pgrep -u zorro\n17985\n17986\n\nAnother pgrep option (-l) will allow you to see a user's process IDs along with the name of each process. The additional information can be extremely handy.\n$ pgrep -u xyz\n24201\n24311\n24312\n$ pgrep -u xyz -l\n24201 bash\n24311 bash\n24312 vim\n\nYou can also look at multiple users at a time if you like, simply by separating their usernames with commas.\n$ pgrep -u xyz,apache,zorro -l\n10596 httpd\n10597 httpd\n10598 httpd\n10599 httpd\n10600 httpd\n10601 httpd\n10602 httpd\n10603 httpd\n15142 httpd\n17559 httpd\n17985 sshd\n17986 bash\n18194 sshd\n18195 bash\n24201 bash\n24311 bash\n24312 vim\n\nYou can also do something like this if you want to clarify which user is running which of the listed processes.\n$ for user in xyz apache zorro\n> do\n> echo $user\n> pgrep -u $user -l\n> done\nxyz\napache\n24201 bash\n24311 bash\n24312 vim\n10596 httpd\n10597 httpd\n10598 httpd\n10599 httpd\n10600 httpd\n10601 httpd\n10602 httpd\n10603 httpd\n15142 httpd\n17559 httpd\nzorro\n17985 sshd\n17986 bash\n18194 sshd\n18195 bash\n\nAnd, if you want to display only the oldest or the newest of the processes being run by some particular users, use the -n (newest) or the -o (oldest) option.\n$ pgrep -u root -o -l\n1 init\n$ pgrep -u root -n -l\n18192 sshd\n\nYou can also list process IDs for processes being run on some particular terminal.\n$ pgrep -t pts\/0\n17986\n$ pgrep -t pts\/0 -l\n17986 bash\n\nIf pgrep can be said to have a "partner in crime," that partner is pkill -- the command that makes terminating processes easier because you don't have to look up the process IDs before issuing the needed kill commands. In fact, these two commands -- pgrep and pkill -- share nearly all of their options -- with only a few exceptions. These two commands are generally, if not always, a lot more than friends. A quick check can determine that they're the same executable. In the command below, we can see that the commands use the same executable (same inodes).\n$ ls -i \/usr\/bin\/pgrep \/usr\/bin\/pkill\n3257815 \/usr\/bin\/pgrep 3257815 \/usr\/bin\/pkill\n\nMore on pkill soon!