Bogusław Brandys ha scritto:
Michael Van Canneyt wrote:
On Wed, 14 Jun 2006, Andreas Berger wrote:
Does Lazarus have a cross-platform way of guaranteeing that only one
instance of the program can run? I know how to do this in windows
but would like to use a cross-platform approach for my Lazarus apps.
It would also be nice (but not necessary) if I could receive a
handle or other access method of the first running instance.
You can do the same as on Windows, only the actual calls will differ.
It would be nice to wrap these calls in a component...
Michael.
Good news is that in Turbo Power OnGuard component that I'm porting to
fpc/lazarus there is a unit for this.However under linux there is no
certain way to do it.It is done by using defined filename but
unfortunately there is no way to automatically delete this file on
crash.When application crashes this file must be removed manually :-(
I have found also situation when mutex used under windows is not
released when application hang (this is however rare)
Faced with the same problem, I've found much more practical, under
linux, to launch the application by means of a wrapper script, which
takes care of that.
Sort of:
1) verify that lock file isn't there, and exit if such.
2) create lock file
3) launch the application
4) delete lock file.
Step 4 is executed when the application terminates, no matter if
normally or because of a crash.
The lock file should be however deleted ad startup, in case of system
crash. This can be achieved taking advantage of what rc.sysinit does for
other similar files (/tmp/.Xsomething will do).
If the launcher script is in the search path, while the actual
executable is not, then it's most unlikely that a normal user will be
able to override the script.
I should be possible to do the same under Windows, using a batch file
with similar logic as a launcher.
Giuliano
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives