I'm writing a php file that -via crontab- gets executed once every minute to send out mails. I'm not being able to device a method to prevent multiple instances of this program from running simultaneously. I only want ONE instance at a time.
My logic is:
1) Get all running processes using "ps auxwww" (plus some awk magic to get only pids for the specified file)
2) If there is more than one process running, meaning there is me, plus another process, exit gracefully.
The problem is that when I run this (see the code window below), I can ONLY see the process id of the currently running php file and none other. Even without filtering anything out, the output of ps auxw only has one process!
I'm guessing there is some sort of user permission thing going on. How can I go around this?
Context: Dedicated server running Red Hat Enterprise Linux 4 with PHP 5.2.9. I have root shell access.
// over simplified version
echo exec("ps auxw");