Sunday, December 22, 2024
HomeUNIXKeep watch on the number of instances of a process

Keep watch on the number of instances of a process

During troubleshooting, it may be helpful to monitor the number of process instances to see if it is stable or increasing.


The following command will display the number of occurrences of sendmail processes every 5 seconds in Bourne shell derivatives (i.e., sh, ksh, bash…):

while true
do
ps -ef | grep [s]endmail | wc -l
sleep 5
done

Using a loop from the command line is a powerful tool. When you press ENTER at the end of each line, you will be presented with a different prompt based on your shell indicating that it is continuing the command and waiting for more.

The [s] in sendmail represents a regular expression trick that means match any single character within the square brackets. This means that [s]endmail will match only sendmail and will prevent counting the grep command in the ps -ef listing because it will show up as [s]endmail.

You can vary the parameter to sleep to increase or decrease the number of seconds between each counting.

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!