[Gambas-user] Send a signal do a PID. Is it possible?

Ongytenes ongytenes at ...626...
Fri Feb 21 19:49:19 CET 2014


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.




-----
Ongytenes
--
View this message in context: http://gambas.8142.n7.nabble.com/Send-a-signal-do-a-PID-Is-it-possible-tp1017p45815.html
Sent from the gambas-user mailing list archive at Nabble.com.




More information about the User mailing list