Another idea is this:
Create a "lock" subdirectory within /var
Create a script to launch the application. When the application is launched, touch a file inside the lock directory. I'd do something like the date, the user, the instance number of the application, and perhaps the application name (for good measure). Something like:
When the application ends, have the script delete the appropriate lock file.
Before the application runs, you can ls the directory, do some grep'ing and cut'ing on the filenames, and count how many users have the application open. Then you can allow the application to run, or error out with a "too many users" message.
Adding the date gives you a safeguard against lost processes (abnormal exit or whatever). If you see a lock that's older than, say, a week, then you can probably get rid of it.
To be even more careful, you could write the process ID of the application to the lock file. That way, you can have a cron job check the lock directory's files versus actual running processes. If they don't match up, then you can delete the lock file safely; automated cleanup.
I haven't given much thought to the code, and will repost later if i get some time.
Last edited by Dark_Helmet; 07-31-2003 at 11:50 AM.