My way to check if a progam is already running - Linux

This is a discussion on My way to check if a progam is already running - Linux ; Jan Panteltje writes: > On a sunny day (Mon, 25 Jun 2007 13:57:55 +0200) it happened Rainer Weikusat > wrote in : >>Jan Panteltje writes: >>> On a sunny day (Mon, 25 Jun 2007 10:30:28 +0200) it happened Rainer Weikusat ...

+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3
Results 41 to 56 of 56

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

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

    Jan Panteltje writes:
    > On a sunny day (Mon, 25 Jun 2007 13:57:55 +0200) it happened Rainer Weikusat
    > wrote in <87bqf4b60s.fsf@fever.mssgmbh.com>:
    >>Jan Panteltje writes:
    >>> On a sunny day (Mon, 25 Jun 2007 10:30:28 +0200) it happened Rainer Weikusat
    >>> wrote in <87k5tsbfmj.fsf@fever.mssgmbh.com>:
    >>>
    >>>>Jan Panteltje 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?


    *fer crissake* 'the second loop' refers to THE SECOND LOOP, not to the
    second iteration of the first loop ...


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

    On a sunny day (Mon, 25 Jun 2007 16:05:15 +0200) it happened Rainer Weikusat
    wrote in <873b0gb04k.fsf@fever.mssgmbh.com>:
    >> If it did not succeed, but errno was EAGAIN then what would you do?

    >
    >*fer crissake* 'the second loop' refers to THE SECOND LOOP, not to the
    > second iteration of the first loop ...


    So you get religious about it... I as refering to the second loop.
    man lockf

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

    Jan Panteltje writes:
    > On a sunny day (Mon, 25 Jun 2007 16:05:15 +0200) it happened Rainer Weikusat
    > wrote in <873b0gb04k.fsf@fever.mssgmbh.com>:
    >>> If it did not succeed, but errno was EAGAIN then what would you do?

    >>
    >>*fer crissake* 'the second loop' refers to THE SECOND LOOP, not to the
    >> second iteration of the first loop ...

    >
    > So you get religious about it... I as refering to the second loop.
    > man lockf


    Then please be so kind to refrain from abusing my postings to talk
    about totally unrelated stuff in future.


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

    On a sunny day (Mon, 25 Jun 2007 17:45:40 +0200) it happened Rainer Weikusat
    wrote in <87y7i89gwr.fsf@fever.mssgmbh.com>:

    >Jan Panteltje writes:
    >> On a sunny day (Mon, 25 Jun 2007 16:05:15 +0200) it happened Rainer Weikusat
    >> wrote in <873b0gb04k.fsf@fever.mssgmbh.com>:
    >>>> If it did not succeed, but errno was EAGAIN then what would you do?
    >>>
    >>>*fer crissake* 'the second loop' refers to THE SECOND LOOP, not to the
    >>> second iteration of the first loop ...

    >>
    >> So you get religious about it... I as refering to the second loop.
    >> man lockf

    >
    >Then please be so kind to refrain from abusing my postings to talk
    >about totally unrelated stuff in future.


    Look idiot, I started this thread, post some code if you can do better else shut the **** up.

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

    On Jun 25, 4:10 am, Jan Panteltje wrote:

    > 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 have see errno values been used wrongly before.
    > It is just playing safe.


    Err, what?! EAGAIN does not mean "test again", it means the file is
    locked. Since that was what you wanted to know, ...

    You seem *extremely* confused.

    DS


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

    On a sunny day (Mon, 25 Jun 2007 14:31:06 -0700) it happened David Schwartz
    wrote in
    <1182807066.946422.180340@k79g2000hse.googlegroups. com>:

    >On Jun 25, 4:10 am, Jan Panteltje wrote:
    >
    >> 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 have see errno values been used wrongly before.
    >> It is just playing safe.

    >
    >Err, what?! EAGAIN does not mean "test again", it means the file is
    >locked. Since that was what you wanted to know, ...
    >
    >You seem *extremely* confused.


    Na, it says:

    F_TEST Test the lock:
    return 0 if the specified section is unlocked or locked by this process;
    return -1, set errno to EACCES, if another process holds a lock.

    Not a word on the other error codes here, but further down:
    ERRORS
    EAGAIN The file is locked and F_TLOCK or F_TEST was specified,
    or the operation is prohibited because the file has been memory mapped by another process.
    etc for other errors.

    I guess there are several ways one can read that man 3 lockf.
    That is why one should look at the source.

    So, basically if lockf returns -1 and errno is not EACCESS then some problem must exists.

    I have tried several varieties of the code, both testing for EACCES and testing for EAGAIN.
    I suggest you try some before you criticise,

    Else it is just untried blabber.

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

    On Jun 25, 2:49 pm, Jan Panteltje wrote:

    > EAGAIN The file is locked and F_TLOCK or F_TEST was specified,
    > or the operation is prohibited because the file has been memory
    > mapped by another process.
    > etc for other errors.


    In other words, some other process is using the file. This is exactly
    what you were testing for, so you have your answer.

    > I have tried several varieties of the code, both testing for EACCES and testing > for EAGAIN.
    > I suggest you try some before you criticise,
    >
    > Else it is just untried blabber.


    Your code is broken. EAGAIN gives you your answer, there is no reason
    to retry.

    DS


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

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFGgFqzVcFcaSW/uEgRAukoAKCHJ+C+Ul0Bn2qqUwPF1K2GOp4cNACdHQeF
    aZsllgi5YzMXn3HrMgmqJRg=
    =03Zd
    -----END PGP SIGNATURE-----

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

    On Jun 24, 3:47 am, Rainer Weikusat wrote:

    > It is still racy, though, because an
    > instance that is just starting up could be prevented from really
    > running by one that is just in the process of dying, but still holds
    > the lock.


    That is not a race. A race condition occurs when doing A and B at the
    same time can result in something different from what would happen if
    either you did A then B or if you did B then A. In the instant case,
    the result is the same as if you started the second process and then
    stopped the first. So there is no race condition.

    Suppose you start two instances at the same time. If you started A
    then B, A would run. If you started B then A, B would run. If you
    start them both at the same time, and something *else* happens (such
    as both running or neither running), *that* is a race condition.

    In this case, the one just starting up could be prevented from
    running. But that's exactly what should happen if you start it first.
    So there's no race condition, it's a valid outcome.

    DS


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

    Jan Panteltje writes:
    > On a sunny day (Mon, 25 Jun 2007 17:45:40 +0200) it happened Rainer Weikusat
    > wrote in <87y7i89gwr.fsf@fever.mssgmbh.com>:
    >
    >>Jan Panteltje writes:
    >>> On a sunny day (Mon, 25 Jun 2007 16:05:15 +0200) it happened Rainer Weikusat
    >>> wrote in <873b0gb04k.fsf@fever.mssgmbh.com>:
    >>>>> If it did not succeed, but errno was EAGAIN then what would you do?
    >>>>
    >>>>*fer crissake* 'the second loop' refers to THE SECOND LOOP, not to the
    >>>> second iteration of the first loop ...
    >>>
    >>> So you get religious about it... I as refering to the second loop.
    >>> man lockf

    >>
    >>Then please be so kind to refrain from abusing my postings to talk
    >>about totally unrelated stuff in future.

    >
    > Look idiot, I started this thread, post some code if you can do
    > better else shut the **** up.


    See, this is Usenet, meaning, people use it to discuss about
    stuff. You have posted a code sample which contained a loop without
    purpose. The purpose of me pointing at this was not necessarily to get
    you to understand thar (after all, since you wrote this POS, the chances
    that you ever will are fairly dim), but more because I am interested
    in discussing code. Since you are quite obviously not interested in
    discussing code, you could (stretching credibility quite a bit)
    perhaps try to be a nice person and not waste everybody's time with
    extended postings containing random nonsense. Nobody really cares if
    you have a problem admitting that your coding skills are, let's say,
    'such that they would warrant improvement'. This only prevents you
    from ever learning how to improve them.

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

    On a sunny day (Mon, 25 Jun 2007 16:57:19 -0700) it happened David Schwartz
    wrote in
    <1182815839.808132.9630@z28g2000prd.googlegroups.co m>:

    >On Jun 25, 2:49 pm, Jan Panteltje wrote:
    >
    >> EAGAIN The file is locked and F_TLOCK or F_TEST was specified,
    >> or the operation is prohibited because the file has been memory
    >> mapped by another process.
    >> etc for other errors.

    >
    >In other words, some other process is using the file. This is exactly
    >what you were testing for, so you have your answer.
    >
    >> I have tried several varieties of the code, both testing for EACCES and testing > for EAGAIN.
    >> I suggest you try some before you criticise,
    >>
    >> Else it is just untried blabber.

    >
    >Your code is broken. EAGAIN gives you your answer, there is no reason
    >to retry.
    >
    >DS


    No my code works perfectly, immediately.
    What is broken or at least illogical is their use of errno.
    ;-)

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

    On Jun 26, 4:26 am, Jan Panteltje wrote:

    > >Your code is broken. EAGAIN gives you your answer, there is no reason
    > >to retry.


    > No my code works perfectly, immediately.


    I don't know what to say. You simply refuse to learn anything.

    DS


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

    On a sunny day (Tue, 26 Jun 2007 23:20:23 -0700) it happened David Schwartz
    wrote in
    <1182925223.722048.151210@n2g2000hse.googlegroups.c om>:

    >On Jun 26, 4:26 am, Jan Panteltje wrote:
    >
    >> >Your code is broken. EAGAIN gives you your answer, there is no reason
    >> >to retry.

    >
    >> No my code works perfectly, immediately.

    >
    >I don't know what to say. You simply refuse to learn anything.
    >
    >DS


    If you have nothing to say then don't say it :-)

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

    On a sunny day (Wed, 27 Jun 2007 09:00:53 +0100) it happened
    =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= wrote in
    :

    >David Schwartz writes:
    >
    >> On Jun 26, 4:26 am, Jan Panteltje wrote:
    >>
    >>> >Your code is broken. EAGAIN gives you your answer, there is no reason
    >>> >to retry.

    >>
    >>> No my code works perfectly, immediately.

    >>
    >> I don't know what to say. You simply refuse to learn anything.

    >
    >You've been around here long enough to recognise him as the idiot he
    >is. Just ignore him.


    You are the idiot, no code, no example, no theory, just insults.
    Go spam alt.idiots.




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

    David Schwartz writes:

    > On Jun 26, 4:26 am, Jan Panteltje wrote:
    >
    >> >Your code is broken. EAGAIN gives you your answer, there is no reason
    >> >to retry.

    >
    >> No my code works perfectly, immediately.

    >
    > I don't know what to say. You simply refuse to learn anything.


    You've been around here long enough to recognise him as the idiot he
    is. Just ignore him.

    --
    Måns Rullgård
    mans@mansr.com

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


    Jan Panteltje wrote:

    > On a sunny day (Tue, 26 Jun 2007 23:20:23 -0700) it happened David Schwartz
    > wrote in
    > <1182925223.722048.151210@n2g2000hse.googlegroups.c om>:


    > >I don't know what to say. You simply refuse to learn anything.


    > If you have nothing to say then don't say it :-)


    That's not a good idea, because the type of nonsense you are spouting
    can actually do harm. It's important that knowledgeable, experienced
    people at least post a warning to others that they should not do as
    you do.

    DS


+ Reply to Thread
Page 3 of 3 FirstFirst 1 2 3