in reply to Detect options of script runnning in a demon mode
One classic way of handling this problem is to have the daemon acquire a lock on a specific resource, and usually things are set up so that the lock is automatically released when the process exits. The challenge in your case is to come up with a command line -> resource mapping which will do what you want.
One simple idea is to map the command line to a file path. For instance, map "-a 1 -b 2 -c 3" to "/some/dir/locks/-a 1 -b 2 -c 3". Then use flock or File::lockf to obtain an exclusive lock on that file. You'll have to make sure that the path will work in all cases (e.g. be careful of special characters in your command line, path length, etc.) Another option is to use mysql's locking feature which allows you to identify a resource by an arbitrary string.
Some issues I'll think you'll run into:
In general when I've had to do this I've only needed a couple of different locks per daemon -- most of the time just one. If you tell us more about your application and its possible command line arguments, we can advise you on the what the best locking mechanism would be.
|
|---|