[Gambas-user] donot permit another instance of my program

Rolf-Werner Eilert rwe-sse at osnanet.de
Thu May 31 16:49:43 CEST 2018


Piccoro, you are right, a complete solution would then

- check for dbus, and if it isn't there:
- check for pgrep, and if it isn't there:
- use a lock file

Regards
Rolf

Am 31.05.2018 um 15:59 schrieb PICCORO McKAY Lenz:
> Hans, the dbus interface are not a default neither! specially if my 
> program its a daemon in a efficient linux and not a stupid systemd 
> windo-like-redhat linux
> 
> Lenz McKAY Gerardo (PICCORO)
> http://qgqlochekone.blogspot.com
> 
> 2018-05-31 5:57 GMT-04:00 Hans Lehmann <hans at gambas-buch.de 
> <mailto:hans at gambas-buch.de>>:
> 
>     Hello,
> 
>     the given solutions both have a small hook. The 'pgrep' program is
>     not installed by default on all systems. The variant with the look
>     file runs empty if the program crashes at runtime and the created
>     look file can no longer be deleted. The presented variant does not
>     require much effort and works well to reliably prevent a second
>     program start.
> 
>     FMain.class
> 
>     ' Gambas class file
> 
>     Public hObject As DBO ' D-Bus-Object
> 
>     Public Sub _new()
> 
>        Dim sMessage As String
>        DBus.Unique = True
> 
>        hObject = New DBO
>        Try DBus.Session.Register(hObject, "/Export1")
>        If Error Then
>           sMessage = Subst("&1 '&2' &3", ("The program"),
>     Application.Name, ("has already been started!"))
>           Message.Warning(sMessage)
>           Me.Close()
>        Endif
> 
>     End
> 
>     Public Sub Form_Open()
>        FMain.Resizable = False
>     End
> 
>     Public Sub Form_Close()
>        If DBus.IsRegistered(hObject) Then DBus.Session.Unregister(hObject)
>        Me.Close()
>     End
> 
>     ------------------------------------------------------------------------
> 
>     DBO.class
> 
>     ' Gambas class file
> 
>     Inherits DBusObject
>     Create Static
> 
>     ' The class can remain empty from here on...
> 
>     ------------------------------------------------------------------------
> 
> 
> 
>     With kind regards
> 
>     Hans
>     www.gambas-book.net <http://www.gambas-book.net>
> 
> 
>     ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
> 
> 
> 
> 
> 
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
> 



More information about the User mailing list