[Gambas-user] Avoiding multiple instances

Stefano Palmeri rospolosco at ...152...
Fri Feb 1 13:42:50 CET 2008


Alle 13:31, venerdì 1 febbraio 2008, Benoit Minisini ha scritto:
> On vendredi 1 février 2008, Stefano Palmeri wrote:
> > Alle 18:38, giovedì 31 gennaio 2008, Epíleg ha scritto:
> > > 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.
> >
> > I found out that using Application.Args[0] is better,
> > because we don't have to care if the user renames the binary.
> >
> > PUBLIC SUB Main()
> >
> >    DIM sShellOutput AS String
> >
> >      SHELL "ps aux | grep  -w " & Application.Args[0]&
> >          " | grep -wv grep | wc -l" TO sShellOutput
> >
> >      IF Val(sShellOutput) > 1 THEN QUIT
> >
> > END
> >
> > Stefano
>
> I have a 'pgrep' command on my system for finding a process from its name
> (and many other things).
>
> Regards,

Yes, but it seems that pgrep (as pidof) can't manage a Gambas binary. That's 
why I use "ps aux | grep blahblah". 

Stefano




More information about the User mailing list