I know this question has been asked already but I either didn't understand the answer or it didn't apply to me.
I have a php script that I am calling every 1 minute using CPanel to set up the Cron Job. The nature of the script means that it could overrun for just over the minute so I need to know how to stop the next one running if the first one hasn't completed.
I have a VPS running CENTOS 5.5 and have access to WHM and CPanel. I have never used Linux before (only just got the server yesterday) so I have no idea what I am doing and would appreciate some help if possible. If I need to provide more information please let me know (I don't know what info you would need at the moment).
Thanks.
Use a bash script as your cron job
cron.sh
Please see Process Management. You will probably want to use a lock file. You can use
flock
for example.Why can't you let your jobs complete?
Your questions says "I either didn't understand the answer or it didn't apply to me", but you don't say in what way. Please be more specific.
Docs: https://www.timkay.com/solo/
Example
I am curious if implementing something with ps will solve the issue. Would simple
ps -e | grep script_name.php | awk '{print $4}'
be sufficient? It definitely will tell you if the script is running, no need to check if someone killed it beforehand. How creating and then removing a lock file is better/faster than this?I am not sure, just want to know pros and cons. Thanks