[Gambas-user] Avoiding multiple instances

Stefano Palmeri rospolosco at ...152...
Fri Feb 1 09:38:15 CET 2008


Alle 02:38, venerdì 1 febbraio 2008, Jeffrey Cobb ha scritto:
> All these ideas give me...an idea.
>
> Is there a way to find out the PID of the gambas program that is
> running?
>
> Thanx again!
> Jeff

Hi. This example returns all the PIDs of different
instances of the same program. If you need just the PID of the current
application you could use Application.Id.

PUBLIC SUB Main()
  
  DIM sShellOutput AS String
  DIM arsPIDs AS String[]
  DIM sOnePID AS String
  
  arsPIDs = NEW String[]
  
  SHELL "ps ax | grep -w " & Application.Name & ".gambas" & 
        " | grep -wv grep | cut -f2 -d' '" TO sShellOutput 
  
  arsPIDs = Split(sShellOutput, "\n", "", TRUE)
  
  FOR EACH sOnePID IN arsPIDs
     PRINT sOnePID
  NEXT   
  
  IF arsPIDs.Count > 1 THEN QUIT   
  
END

Stefano

>
> On Thu, 2008-01-31 at 18:38 +0100, Epíleg wrote:
> > En/na Stefano Palmeri ha escrit:
> > > Alle 16:45, giovedì 31 gennaio 2008, Stefano Palmeri ha scritto:
> > >> I use this simple code:
> > >>
> > >> PUBLIC SUB Main()
> > >>
> > >>   DIM sShellOutput AS String
> > >>
> > >>   SHELL "ps aux | grep " & Application.Name & ".gambas" & " | grep -v
> > >> grep" TO sShellOutput
> > >>
> > >>   IF sShellOutput THEN QUIT
> > >>
> > >> END
> > >
> > > or better:
> > >
> > > PUBLIC SUB Main()
> > >
> > >   DIM sShellOutput AS String
> > >
> > >   SHELL "ps aux | grep " & Application.Name & ".gambas" &
> > >         " | grep -wv grep | wc -l" TO sShellOutput
> > >
> > >   IF Val(sShellOutput) > 1 THEN QUIT
> > >
> > > END
> >
> > Very good solution. Thanks a lot!
> >
> > Epíleg.
> >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user




More information about the User mailing list