[Gambas-user] Avoiding multiple instances

Stefano Palmeri rospolosco at ...152...
Sat Feb 16 11:55:50 CET 2008


Alle 11:22, sabato 16 febbraio 2008, Rolf-Werner Eilert ha scritto:
> Stefano Palmeri schrieb:
> > And so finally :-) , to avoid multiple instances we could do:
> >
> > PUBLIC SUB Main()
> >
> >   DIM sShellOutput AS String
> >
> >   SHELL "pgrep -f " & Application.Args[0] TO sShellOutput
> >   IF Split(Trim$(sShellOutput), "\n").Count > 1 THEN QUIT
> >
> > END
> >
> > Stefano
>
> This is not multiuser-safe unfortunately. I just tested it here, and if
> the second user starts the program, it refuses to come up.
>
> Of course it does, as this asks for the name of the program only. So I
> improved the thing by adding "-u":
>
> SHELL "pgrep -f -u " & User.ID & " " & Application.Args[0] TO sShellOutput
>
> Now I've got two questions for the experts:
>
> First, my program lacks a SUB Main() but it worked within Form1_Load()
> as well. Is that ok? I ask because if started from a terminal, Gambas
> says 31 allocations not freed etc. (I am using the HighlightEditor
> example for this).
>
> Second, maybe it's better to use "-U" instead of "-u", what is the
> difference?
>
> Hope someone still follows this thread... :-)
>
> Rolf
>

To understand the difference between "-u" and "-U", try to
run a SUID application, I mean an application that you can run
as normal user and gives you root privileges:

"-u" normal_user SUID_application *doesn't* return anything.

"-U" normal_user SUID_application returns the process 

I definitively prefer "-U" option, that manages the user that launches
the application. 

Stefano
 
 







> -------------------------------------------------------------------------
> 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