[Gambas-user] Single instance application, anyone else done it?

Tobias Boege tobs at taboege.de
Thu Jul 8 19:27:32 CEST 2021

On Thu, 08 Jul 2021, Bruce Steers wrote:
> 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)

This works until someone copies the program to a different
location and starts both, the original and the copy. Then,
pgrep will not be able to tell you that these two are in
fact the same program because the executables and hence
the command lines matched by pgrep are different.

This is probably an okay assumption to make (that people who
make and run copies of the executable are asking for trouble),
but one should be aware of making this assumption when using
the pgrep method.


"There's an old saying: Don't change anything... ever!" -- Mr. Monk

More information about the User mailing list