I have a process run by cron every hour. Such process calls another one (not sourced), ie: ./childProc.sh (Not sure if this detail is important)
Because of an endless loop in child process (which I'm still trying to find out why it does not end), I have to kill all processes related before run it again.
I've found this post and this article (Kill PPIDs section), but I don't understand the difference between: kill -9 -$PPID
and kill -9 -- -$PPID.
My questions are:
What means here --? On the other hand, is -9 (SIGKILL) the right signal to kill a bash script process or is it too strong?
And lastly, my approach to check that behaviour (whether a process is still running) is creating a file that contains PID and PPID:
#!/bin/bash
# PID FILE
PID_FILE="$BASE_BACKUP_DIR"/".pid.$HOSTNAME";
## If exists PID_FILE, kill
if [[ -f "PID_FILE" ]]; then
pid_last=$(head -1 | cut -d " " -f1);
ppid_last=$(head -1 | cut -d " " -f2);
echoErr "Process is still running. Parent $ppid_last, child: $pid_last. ";
kill -9 -- -"$ppid_last";
fi;
## Create PID file
echo "$$ $PPID" > "$PID_FILE";
####### All process #######
# at the end, delete PID_FILE
rm -f "$PID_FILE";
exit 0;
What do you think? Any improvement?