How to find out if there is already another instance of my application running ?
Your application must do something so that the 2nd instance can detect it.
One way would be to scan /proc. You need to recurse into every directory, open the as file and use the devctl DCMD_PROC_MAP_DEBUG_BASE to get the info.
That is not 100% since if the executable is renamed you are screwed.
There are other method like create a resources of some kind, name, pipe, file, etc then on startup check if that resource already exists.
Maybe it’s possible to setup a read-lock on the executable, never tried that.
Your application must do something so that the 2nd instance can detect it.
I know that ( and I think that everybody knows that ),
but I don’t know what exactly I should use ?
/named semaphore, resmgr, file, … ?
I found example, but it works only in Photon
and I need sth for Neutrino:
qnx.com/developers/docs/6.3. … onnections
“This application uses a connector to determine if there’s already another instance of the application running.”
I tried named semaphore ( sem_open() / sem_unlink() )
but after termination signals (for example SIGKILL) it (semaphore) still exists,
snd some signals cannot be handled.
I think name_attach() a local name is the only way to exclusive 2 processes.
open() a file O_EXCL in theory should also work, but I think somebody figured out a very small race condition with that…
I’m going to second using name_attach(). This assumes that you have access to the source code of the application you’re trying to detect. Once you’ve done a name attach you can just check that a file exists in /dev/name/local.
App you want to detect, add:
name_attach_t *attach;
attach = name_attach(NULL, "app_name", 0);
if (attach == NULL){
// do something to handle the failure here.
}
In detector app:
if (access("/dev/name/local/app_name", F_OK) == 0){
// Process is running
}
-James Ingraham
Sage Automation, Inc.
You can use the resource database (rsrcdbmgr_*) calls to have the app uniquely register a name and get back a devno value. If the minor isn’t zero, then someone else is running.
thanks!
name_attach() + access() works perfectly!
/that’s exactly what I was looking for
That may well be the first time I have ever sucessfully helped someone on the Internet. I feel validated!
-James Ingraham
Sage Automation, Inc.