Re: My way to check if a progam is already running
- From: Jan Panteltje <pNaonStpealmtje@xxxxxxxxx>
- Date: Mon, 25 Jun 2007 13:17:58 GMT
On a sunny day (Mon, 25 Jun 2007 13:57:55 +0200) it happened Rainer Weikusat
<rweikusat@xxxxxxxxxxx> wrote in <87bqf4b60s.fsf@xxxxxxxxxxxxxxxxx>:
Jan Panteltje <pNaonStpealmtje@xxxxxxxxx> writes:
On a sunny day (Mon, 25 Jun 2007 10:30:28 +0200) it happened Rainer Weikusat
<rweikusat@xxxxxxxxxxx> wrote in <87k5tsbfmj.fsf@xxxxxxxxxxxxxxxxx>:
Jan Panteltje <pNaonStpealmtje@xxxxxxxxx> writes:
[...]
/* test if file is locked */
i = 0;
while(1)
{
a = lockf(fileno(lockfile), F_TEST, 0);
if(a != -1) break;
if(errno != EAGAIN)
{
fprintf(stderr, "MyProgram: An other MyProgram is already running, aborting.\n");
exit(1);
}
i++;
if(i == 1000) // 10 S
{
fprintf(stderr, "MyProgram: timeout EAGAIN waiting for lockf() F_TEST, aborting.\n");
exit(1);
}
usleep(10000); // 10 ms
}
This loop is totally useless, because by the time you do the second
lockf call, the file may or may not be locked and it doesn't matter
what another lockf call happening in the past returned.
EAGAIN means test again, and I have tested this soft and forced the EAGAIN condition.
Unless (we still have to look at the lockf() source) EAGAIN is used
wrongly, the loop is correct.
I didn't claim it was wrong but that it wouldn't do anything useful.
Which it doesn't. The 'real test' is the lock(..., F_TLOCK in the
second loop and that will or will not succeed, no matter how many
times F_TEST succeeded or didn't succeed before.
If it did not succeed, but errno was EAGAIN then what would you do?
Ignore errno? This can be done.
The issue was that we are not sure if something happened that required
the test to run again.
That depends on the code of lockf().
As I did not write lockf() and am not in the mood to go find the source,
from this follows it is much earier to write your own OS and ppas.
.
- Follow-Ups:
- Re: My way to check if a progam is already running
- From: Rainer Weikusat
- Re: My way to check if a progam is already running
- References:
- My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Michal Nazarewicz
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Rainer Weikusat
- Re: My way to check if a progam is already running
- From: Jan Panteltje
- Re: My way to check if a progam is already running
- From: Rainer Weikusat
- My way to check if a progam is already running
- Prev by Date: Re: My way to check if a progam is already running
- Next by Date: Re: My way to check if a progam is already running
- Previous by thread: Re: My way to check if a progam is already running
- Next by thread: Re: My way to check if a progam is already running
- Index(es):
Relevant Pages
|
|