[Gambas-user] Single instance application, anyone else done it?
Bruce Steers
bsteers4 at gmail.com
Thu Jul 8 18:40:36 CEST 2021
On Thu, 8 Jul 2021 at 15:59, Tobias Boege via User <
user at lists.gambas-basic.org> wrote:
> On Thu, 08 Jul 2021, John Dovey wrote:
> > Just to throw a spammer in the works, what about those of us who run
> > everything throw X windows and don’t have a desktop at all?
> >
>
> D-Bus does not need a desktop either, it is a message passing mechanism.
> For example, systemd depends on D-Bus, so many systems without a desktop
> or even without a graphical display at all might already run D-Bus.
>
> If you don't want to rely on the presence of D-Bus, there is still the
> "pid file" technique (but you have to handle stale pid files). Or you
> could make your program set up a UNIX socket in a well-known location.
> Other instances of your program will try to connect to the socket and
> if they get a response, another instance is running. If not, they
> create that socket and answer on it to prove that they're running.
>
> Best,
> Tobias
>
i used shell and pgrep
Dim sResult As String
Shell "pgrep -f -d , " & Application.Name To sResult
that returns a list of running application Id's matching the app separated
by commas
You can then...
Dim sIDs As String[] = Split(sResult, ",")
if sIDs.Count=1 (only one app loaded)
If SIDs.Count>1 Then
then the application chooses the lowest number PID and selects it as the
master app.
Dim iLowPID as Integer = Val(sIDs[0])
For i As Integer = 1 To SIDs.Max
iLowPID = Min(iLowPID, Val(sIDs[i]))
Next
If iLowPID = Application.Id (then this app is master)
I've an example of doing this and using a pipe to send the master app the
args on the gambas.one forum..
https://forum.gambas.one/viewtopic.php?f=13&t=943
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210708/a5693778/attachment.htm>
More information about the User
mailing list