I have created an application that is basically a deamon written in C. It is stopped and started using a shell script. Specifically, to stop it, kill is used to send a SIGTERM signal. The PID of the daemon is stored in a file on the disc in the format:
1234\n
A user reports that they cannot stop the daemon, the shell script returns the error:
kill: `': not a pid or valid job spec
The PID is fetched and used in the shell script as follows:
if [ -f "${PID_FILE}" ]
then
FCPID=`head -n 1 $PID_FILE`
kill -n SIGTERM "${FCPID}"
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
rm -f ${PID_FILE}
echo "OK"
else
echo "FAIL"
exit 1
fi
else
echo "Wasn't running"
exit 1
fi
It works fine on my machine (Ubuntu 10.04) and so far no one else has reported this problem. Does anyone recognise the error or is there a mistake in the shell script that could cause problems on some platforms?
That error occurs when you pass
killan empty arg as a PID, i.e.My guess is your script throws up that error when the PID_FILE exists but is empty, hence
${FCPID}ends up as an empty string.Check that the start script is actually writing out the PID_FILE correctly on your user’s machine.