This seems like an ideal use case for crontab. I'd write 2 bash scripts that run every 3 hours via cron. So something like the following:
#ScriptA.sh
ifProcessRunning
KillProcess
#ScriptB.sh
ifProcessNotRunning
StartProcess
#CronTab
0,6,12,18 * * * * ScriptA.sh
3,9,15,21 * * * * ScriptB.sh
For killing the process you can use any normal unix command, so piping a ps aux
and running kill within the shell script could work.
Hopefully this helps -- comment if you want me to flesh things out more!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…