[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug report in command ( ps -ef | grep "myTask" | grep -v "grep" | wc
Re: bug report in command ( ps -ef | grep "myTask" | grep -v "grep" | wc -l )
Fri, 25 Feb 2005 09:26:55 -0700
OSK Lu Jun wrote:
> To: address@hidden, address@hidden, address@hidden, address@hidden
> To whom it may concern
Please do not cross post to so many unrelated groups. Especially when
asking for help it is more appropriate to pick a specific forum. If a
particular one does not produce an answer is is okay to try a
> are alive. In bash file I use the COMMAND
> ( PROCESS_NUM=`ps -ef | grep "myTask" | grep -v "grep" | wc -l` )
> to judge the alive status of my executable programs.
I see that type of thing frequently, where users use grep once and
then again to remove the grep itself from the process listing. That
is not needed. It is better written differently. It is better to
avoid the need at all.
1. It is better written different. The '-f' option of ps produces a
full listing. But this is the cause of grep showing up in the list
and users wanting to remove the grep. So don't use the -f option.
Use only the -e option and only look at the program name. I prefer
awk for this task.
ps -u root -e | awk '$NF=="myTask"'
2. Better to avoid this type of test at all. It is easy to be fooled
by processes that happen to be running with the same name.
Restricting to just the root user processes as in the above example
with '-u root' helps but I think still better to avoid. Better to
have the process write its PID in a file and to check that pid for
being alive in the system.