You may want to prevent the user from spawning multiple copies of your Java application. The Java community would be grateful to anyone who solves this and packages it up as a black box that works on all major platforms and does not require special configuration. I have submitted
Here are seven approaches:
A common approach for Unix and descendants is to use a file with a known absolute pathname that contains the process PID (Process Identifier). The clever trick is that the program that creates the file immediately closes and reopens it for reading and then deletes the file without closing it: this works because file deletion is deferred until there are no longer any processes that have the file open. When a process dies or is killed, all the files it had open are closed. If the file exists and has a different pid to the checker, then another copy is running. There is no clean-up needed: if the user kills the program the file vanishes because it only remains in existence as long as at least one process has the file open.
This page is posted |
http://mindprod.com/jgloss/singleinstance.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\singleinstance.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[18.116.23.59] |
| |
Feedback |
You are visitor number | |