Waiting for a process to die

Nikos Vassiliadis nvass9573 at gmx.com
Sun May 31 21:15:56 UTC 2009


Frank Shute wrote:
> On Sun, May 31, 2009 at 12:42:37PM -0700, Steven Schlansker wrote:
>> Chris Rees wrote:
>>> [ `ps ax |grep pid | wc -l ` = 1 ] && (echo "done!" | Mail -s "PROC
>>> DONE" kelly.terry.jones at gmail.com)
>>>  
>> Not always going to work.  For example,
>>
>> [steven at scs:~]% ps ax | grep init
>>    1 ?        Ss     0:39 init [2] 
>> 13421 pts/1    R+     0:00 grep init
> 
> This is why you should use pgrep(1) to find a PID (and kill it) rather
> than directly grepping a ps output like the previous poster did.

Yes, pgrep is the tool. If you already know the pid, you can
use good old ps:
ps 1 && echo init runs




More information about the freebsd-questions mailing list