[Gambas-user] donot permit another instance of my program

PICCORO McKAY Lenz mckaygerhard at gmail.com
Thu May 31 02:33:33 CEST 2018


ok thanks to started point, seems the exec must be more elaborate i manage
with:

ps -lxa | grep " & nameproc & " | sed 's/   */ /g' | cut -d' ' -f3,13,14,15

by example the gambas named program its really executed by gbr so i must
filter by the arguments...

thanks to both now i detect property the already running program..



Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com

2018-05-30 17:38 GMT-04:00 Jussi Lahtinen <jussi.lahtinen at gmail.com>:

> This problem has nothing to do with multi-threading of Gambas.
>
> Anyway, you can solve your problem this way:
>
> When your program starts, check if there is "lock" file written.
>
>  No --> Write a file with the programs pid number on it.
>  Yes --> Check if there exist program with the given pid number.
>           No --> Replace the pid number of the current instance.
>           Yes --> Exit.
>
> This way you can ensure there is only one instance at the time. However,
> if this should apply per system (instead of per user), you need to write
> the lock file with root permissions.
> And thus in that case, it may not be good solution.
>
> This is also one solution, which I use:
>
>   Exec ["pgrep", "-fl", "YourProgram.gambas"] Wait To sOutput
>
>   If Split(Trim$(sOutput), gb.NewLine).Count > 1 Then
>     Message.Error("Only one instance allowed!")
>     Quit
>   Endif
>
>
> Jussi
>
>
>
> On Wed, May 30, 2018 at 9:37 PM, PICCORO McKAY Lenz <
> mckaygerhard at gmail.com> wrote:
>
>> ok taking in consideration that gambas its not multi-thread
>>
>> how can i avoid second instance of my program..
>>
>> in another case, how can i take care of that, if i manage settings file?
>>
>> seems if the file are access by two instacens a lock may cause corruption
>> of data
>>
>> a good example would be great
>>
>>
>> Lenz McKAY Gerardo (PICCORO)
>> http://qgqlochekone.blogspot.com
>>
>>
>> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>>
>>
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180530/c8ce6d31/attachment.html>


More information about the User mailing list