[Gambas-user] Avoiding multiple instances

Rolf-Werner Eilert eilert-sprachen at ...221...
Sat Feb 16 17:44:42 CET 2008


Stefano Palmeri schrieb:
> 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
>  

Thank you, Stefano, that makes it clear to me.


Rolf




More information about the User mailing list