allow only single process to execute my script instead of having more than one process executing the same script

Kinderly Wade
Kinderly Wade used Ask the Experts™
Hi Experts,

I wrote a bash script that will execute my php code every 30 min via cron job. For some reason when check the process via the ps aux | grep myphp.php, I can see more than one process that are running the same php code. Is there a way for me to ensure that there is only a single process that executes my code instead of having more than one process running the same code? Thanks
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
A very common way to do this is to write a PID file when the script starts.    Check to see if there’s an existing file, that tells you that either the script is running, or that a previous execution failed. Remove the file upon successful completion.
Kinderly Wadeprogrammer


Thanks jsaun!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial