preventing multiple instances of applications

How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

Thanks,
Meredith Dill
mdill@aseco.com

Meredith Dill <mdill@aseco.com> wrote:

How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

The programs could attach a name, and only the that successfully attaches
the name gets to run.

Or the programs could do something like open a particular filename with
O_CREAT|O_EXCL – and only the one that succeeds would get to run.

A global variable won’t work – “global variables” are only global
within a particular program (same for, say, link instances of
widgets) – but two, three, ten copies of a program can all run
simultaneously.

-David

QNX Training Services
dagibbs@qnx.com

IMHO, this problem is better treated at the source, that is, “debounce” the
touch. Once a touch event is received, don’t accept another until after a
certain delay.

Meredith Dill wrote:

How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

Thanks,
Meredith Dill
mdill@aseco.com

Agreed, but there are instances where that is not sufficient. We have similar
requirements, but we need to ensure that the same GUI is only run once on a
network of QNX nodes (or on one client when a server has multiple Phindows
sessions). We have found that the registering a global name is the only
foolproof mechanism. I have a nagging doubt about using the file-opening plan
with what happens when the app crashes (or its node goes away, or there is a
power failure etc) and leaves the file open or lying around. The pwlock file
in QNX4 occasionally has this problem as well.

Dean Douthat wrote:

IMHO, this problem is better treated at the source, that is, “debounce” the
touch. Once a touch event is received, don’t accept another until after a
certain delay.

Meredith Dill wrote:

How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

Thanks,
Meredith Dill
mdill@aseco.com

Donald Backstrom <donaldb@cstgroup.com.au> wrote:

Agreed, but there are instances where that is not sufficient. We have similar
requirements, but we need to ensure that the same GUI is only run once on a
network of QNX nodes (or on one client when a server has multiple Phindows
sessions). We have found that the registering a global name is the only
foolproof mechanism. I have a nagging doubt about using the file-opening plan
with what happens when the app crashes (or its node goes away, or there is a
power failure etc) and leaves the file open or lying around. The pwlock file
in QNX4 occasionally has this problem as well.

Registering a global name isn’t foolproof either. If your network gets
“seperated” you could have two applications do so successfully, and even
without that happening, if there are delays in updates, or the two registers
are “simultaneous” enough, both could be told they successfully registered
the global name.

Yes, having a file around could be a problem too – it isn’t a perfect
solution. Of course, if using the file method, the process could put its
pid & nid in the file – then if someone fails the O_CREAT|O_EXCL, they
can do an open for O_RDONLY, read the nid&pid, and try to verify that the
process is still alive, allowing dynamic clean-up for the process death
option.

-David

How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

Thanks,
Meredith Dill
mdill@aseco.com


QNX Training Services
dagibbs@qnx.com

The name attach worked perfectly. Since we won’t be running on a
network, the other issues brought up won’t be a problem.

Meredith

David Gibbs wrote:

Meredith Dill <> mdill@aseco.com> > wrote:
How do I prevent multiple instances of an app from running
simultaneously? The touchscreen we’re using is very sensitive and often
opens two apps when someone clicks on the program icon. Would I check
the link_instance parameter and save it in a global variable? I looked
in the QDN, but all it says is that multiple instances are not
supported, not how to prevent it.

The programs could attach a name, and only the that successfully attaches
the name gets to run.

Or the programs could do something like open a particular filename with
O_CREAT|O_EXCL – and only the one that succeeds would get to run.

A global variable won’t work – “global variables” are only global
within a particular program (same for, say, link instances of
widgets) – but two, three, ten copies of a program can all run
simultaneously.

-David

QNX Training Services
dagibbs@qnx.com