Re: My way to check if a progam is already running



panteltje@xxxxxxxxx writes:

On 23 jun, 15:18, Michal Nazarewicz <min...@xxxxxxx> wrote:
Jan Panteltje <pNaonStpealm...@xxxxxxxxx> writes:
On Sat, 23 Jun 2007 12:05:34 +0200 it happened Michal Nazarewicz
<min...@xxxxxxx> wrote in <871wg3j89d....@xxxxxxxxxxxxxxxx>:

With the above code I think it is not possible to start two instances in
such a way that both will continue running. The worst case is that they
both will abort. (It's still a bug.)

I still don't see why you don't want to lock a file at the start and
unlock it when program terminates. It's way simpler operation:

Yes, but then you have 2 GUI up for example,

??? How locking a file lock differs from getting number of applications
with given name? Simply replace your checking routine with what I wrote
and you have the same functionality but more portable and without any
bugs.

Maybe I do not understand you, but for example in this newsreader
there is not
just _one_ file, there are many (one for each newsgroup, one or more
for each posting, some for fonts, some for other purposes, some to
hold all groups,
some for indexes, for article headers, one for each article body, and
also these
files are created when needed (for example you subscribe to a group or
post a reply, edit a text, what not).

I'm not saying that you have to lock one of the data files, however
if it would be possible for two newsreader operate on the same data
files I think that would be the best option.

What I'm proposing is to create a lock file for example in a directory
with all the data files. That is, if you keep all the configuration and
data files in "~/.my-newsreader" you can create a file
"~/.my-newsreader/.lockfile" (using int fd = create(foo, 0600)) and then
lock it (using flock(fd, LOCK_EX)). If locking succeed (providing that
you are not using NFS) you're the only application if it fails there's
some application running already.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
.



Relevant Pages