1752507 Members
5758 Online
108788 Solutions
New Discussion юеВ

checkproc

 
SOLVED
Go to solution
Ken_109
Advisor

checkproc

Is there a checkproc program available for hpux 11.11? If so where would I find it at?
Thanks
Ken
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: checkproc


Essentially the universal method for doing this is to send a kill -0 PID to the PID that you are interested in. You then examine ${?}; if it's zero then that is a valid process otherwise no. The fundamental problem is that there may be many instances of a given program running. Whicjh one do you really want. Checkproc suffers from that as well and HP-UX lacks a /var/run/xxx.pid file.


kill -0 ${PIDPROC} # e.g. obtained from ps -e
STAT=${?}
if [ ${STAT} -eq 0 ]
then
"Process running"
else
"No process"
fi
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: checkproc

Ken:

If you mean to query whether or not a process (by name) is running or not, I use something like this:

# myproc=inetd
# [ -z "`UNIX95= ps -C initd -o pid= -o comm=`" ] && mailx -s "$myproc is not running!" root < /dev/null

'myproc' is the *basename* of the process you want to query.

If by "check a process" you mean merely to see if it is alive, then, using its pid, do:

# kill -0 2> /dev/null && echo "is alive" || echo "no process"

Substitute the you want to interrogate.

Regards!

...JRF...
Ken_109
Advisor

Re: checkproc

In Linux there is a binary command, called checkproc. It takes an argument of the full pathname and returns 0 if its running,otherwise 1 or greater.

checkproc checks for running processes that use the specified executable.
checkproc does not use the pid to verify a process but the full path of the corresponding program which is used to identify the executable

This is really a nice thing to have when writing a shutdown script.

Thanks,
ken
A. Clay Stephenson
Acclaimed Contributor

Re: checkproc

I am familiar with that Linux program BUT it does suffer from the ambiguity I mentioned. Even using full pathnames there may be N instances of the program running --- so which one are you interested in? Wise developers will always look for more universal answers to a problem rather than an OS specific command. Not even all Linux versions have that command but every UNIX/Linux box on the planet has ps and grep and that is the wise approach (if a little more scripting is required).
If it ain't broke, I can fix that.
Ken_109
Advisor

Re: checkproc

thanks for the input. I guess in the case of a shutdown, I don't really care that there is more than 1 process running. I just want to know if at least 1 is running then proceed to shut them all down appropriately. ps & grep will have to do, plus a bit of scripting.. Yuck..
James R. Ferguson
Acclaimed Contributor

Re: checkproc

Hi (again) Ken:

As Clay mentions, with a little scripting...

You can easily leverage the first technique I showed by taking your the name of your executable and using 'basename' to reduce it to the code I offered.

# myproc=/usr/sbin/inetd
# myproc=`basename $myproc}`
# [ -z "`UNIX95= ps -C $myproc -o pid= -o comm=`" ] && echo "dead" || echo "running"

Regards!

...JRF...
Ken_109
Advisor

Re: checkproc

Points awarded! Short answer - No checkproc. Long answer, a checkproc look alike can be created using scripting.
Thanks to both for your input.
Regards,
Ken