[Gambas-user] Send a signal do a PID. Is it possible?
Tobias Boege
taboege at ...626...
Fri Feb 21 21:44:14 CET 2014
On Fri, 21 Feb 2014, Ongytenes wrote:
> If you want to lock or check if another occurrence of the program is running,
> you can do the following.
>
> I use a simple text file with *Application.ID* stored in it. I normally
> place this file within the application's folder. I usually named the file
> with the application's name and *.lock* as an extension.
>
> When my application starts up I check for the existence of the file. If
> found then I grabbed the ID (the pid number) that is stored in it. I placed
> the ID in a string variable named PID I then used the following code.
>
> DIM PID as String
> DIM IDcheck as String
>
> SHELL "ps -f -p " & PID TO IDcheck
> IF InStr(IDcheck, "name of your application goes here") THEN
> 'code to react another occurance of your application is running here
> 'You can exit, kill the other occurrence, etc.
> Else
> File.Save(Application.Path &/ "application-name.lock", Application.Id)
> 'This creates/overwrites the lock file with current PID. This happens
> only if
> 'if no match is found for the PID that was stored in the lock file.
> EndIF
>
> The ps command is a bash command to check for running processes
> The -f tells it to display a full format listing. This is necessary to check
> against the name of your application.
> The -p tells it to display only the process that is running on the PID
> number you give it.
>
> When I perform a normal exit out of the application, I delete the
> application.lock text file.
>
Is there a hidden question in this post or do you just want to tell us in
case we didn't know?
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list