Stop and start a process every X hours

Hi, I have a parallelized Mathematica program that spans across 8 MathKernels processes running at 100% and one MathKernel (highlighted in blue) running at < 10% that controls the other 8. They look like this on the cluster:

I want to run these process indefinitely, but after a while, because of a Mathematica bug, the program continues to run at 100%, but stop giving me results.

One way to solve that is to kill the the controller MathKernel process (automatically the other 8 process are killed) and start again.

I would like a help on how to make a script that runs a command "C" and then after some time "X" kills the process belonging to me (giovform) called "MathKernel" running at < 10% cpu and then runs "C" again, all this in a loop. Is this possible? Sorry for asking too much.. :confused:

I am using nohup to execute my commands so I can close the terminal window without killing them.

Giovanni

The unsophisticated/brute force (run with nohup)

ex: 0602-132 The specified buffer is empty.
SLEEP_IN_SECS=900  #this is 15 minutes
while (( 1 ))
do
        ps -aef | grep MathKernel | awk '{print $1}' | while read a
        do
        kill ${a}
        done
sleep ${SLEEP_IN_SECS}
done

OR

or in cron (every 15 minutes)

0,15,30,45  *  * * * foo.sh 
#foo.sh
 ps -aef | grep MathKernel | awk '{print $1}' | while read a
        do
        kill ${a}
        done

Thanks!