1837738 Members
3508 Online
110118 Solutions
New Discussion

check process shell

 
Michael Murphy_2
Frequent Advisor

check process shell

We have shells that send test orders through our production machines to confirm that all is OK (sometimes they hang for over 10min =problem). We use a method of execing the process in a sub-shell, saving PIDs in a temp file, and seeing if the pid file is still around after x minutes. We sometimes get false alarms due to timing (I think). Is there a better way to do this - c program with signal interrupts?
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: check process shell

If you have the PID's saved then simply do a

kill -0 ${PID} 2>/dev/null
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Still running"
else
echo "${PID} gone"
fi

This is exactly what one would do from C to determine if a process is still running.

If it ain't broke, I can fix that.
Nicolas Dumeige
Esteemed Contributor

Re: check process shell

Hello,

I once wrote a "parallelisation shell", one master and many extraction slave, the master checking the good ending of the child process with signal.

The master used two trap on user defined signal - and the child sended one signal on completion and another one on error.

It worked but I did get strange beheviour some time and ksh core dumped several time. Maybe it was due to the signal choice, I ended changing for rather less elegant but more stable choice of flag file with list of process.

I guess the file solution can be as bad as the signal solution if a bunch of process want to write at the exact same time. But in your case, it's probably the good way to go.

Cheers

Nicolas
All different, all Unix