[Gambas-user] Single instance application, anyone else done it?
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.
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
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
Dim iLowPID as Integer = Val(sIDs)
For i As Integer = 1 To SIDs.Max
iLowPID = Min(iLowPID, Val(sIDs[i]))
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..
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the User