in reply to Process Already Running

That code doesn't work as described. It returns true if there are any programs running that match.

anyway.

Since you're not locking, you've just created a race condition: if two processes are started at around the same time, they will detect each other and both exit (provided the process name they're testing is static and their own - if the process name changes for some reason, it's possible that they won't detect each other and both will continue running).

Replies are listed 'Best First'.
Re^2: Process Already Running
by Photius (Sexton) on Sep 13, 2007 at 17:35 UTC
    Thanks. I appreciate your reply. In my particular application, the three situations that you mention: 1) match multiple instances 2) both exit 3) neither exit if name has changed, are acceptable or even desirable. I forgot to mention that my scripts will be scheduled by cron to run every minute, but sometimes they will take more than one minute to complete. If one newly starting instance exits unnecessarily, it is ok since it will run again the next minute.

    What would not be acceptable though, would be if they both have the same name but, for some reason neither of them exit. I just figured that it might be less messy than having to deal with lock files, which if I understand the previous threads on the subject, can also have a race condition.