Perl script hangs

Discussion in 'Perl Misc' started by Kurt, Mar 29, 2005.

  1. Kurt

    Kurt Guest

    Hi,

    I have a perl (5.8.3) daemon running that hangs very strangely.

    It will work for 6-12 hours and then it will hang in a way that

    - it won't log anything anymore (I'm logging pretty regularly)
    - logging stops at various points of the code and even: the last
    logged message is often even incomplete!
    - "top" shows me a CPU usage of 99.9% for its process-id

    I have no clue what the process does but it is alive but surely not
    functioning anymore.

    Help is appreciated,
    Kurt
    Kurt, Mar 29, 2005
    #1
    1. Advertising

  2. Kurt

    Peter Wyzl Guest

    "Kurt" <> wrote in message
    news:...
    : Hi,
    :
    : I have a perl (5.8.3) daemon running that hangs very strangely.
    :
    : It will work for 6-12 hours and then it will hang in a way that
    :
    : - it won't log anything anymore (I'm logging pretty regularly)
    : - logging stops at various points of the code and even: the last
    : logged message is often even incomplete!
    : - "top" shows me a CPU usage of 99.9% for its process-id
    :
    : I have no clue what the process does but it is alive but surely not
    : functioning anymore.


    no shebang
    no 'use strict'
    no 'use warnings'
    no variables defined
    no procedural statements
    no print statements
    in fact no anything....

    bit hard to help really....

    :)

    P
    Peter Wyzl, Mar 29, 2005
    #2
    1. Advertising

  3. Kurt

    phaylon Guest

    Kurt wrote:

    > Help is appreciated


    "You are doing something wrong, maybe." *scnr*.

    For maybe real help: Do you check the return values of your open's,
    close's and so on? Do you use warnings and strict? Have you turned off
    buffering (per C<$|++>)? So you could maybe see more exactly where your
    script hangs.

    Without codeparts there's nothing else that would come into my mind at
    this point. Maybe you find something in common on the parts that stopped
    working.

    hth,p

    --
    http://www.dunkelheit.at/
    bellum omnium pater.
    phaylon, Mar 29, 2005
    #3
  4. Kurt

    Kurt Guest

    Kurt wrote:
    > I'll post again if I can define the part of the code where the error
    > (hope it's a singe error source) occurs.
    >


    I'm back with a short feedback like I promised. I found my error.

    I had a while loop with a counter like this:

    counter = 0;
    while ($array[$counter])
    {
    ...
    if (some_statement)
    {
    ...
    $counter++;
    }
    }

    In this short version of the code it is easy to see what happens if
    the "some_statement" never evaluates to true --> endless loop. But it
    was not that obvious to me in the "long" version of the code :)

    Thanks for the advice with the diabling of perl's buffering, so I
    could enclose the error very precisely!

    Kurt
    Kurt, Apr 1, 2005
    #4
  5. Kurt

    Anno Siegel Guest

    Kurt <> wrote in comp.lang.perl.misc:

    > I had a while loop with a counter like this:
    >
    > counter = 0;
    > while ($array[$counter])
    > {
    > ...
    > if (some_statement)
    > {
    > ...
    > $counter++;
    > }
    > }
    >
    > In this short version of the code it is easy to see what happens if
    > the "some_statement" never evaluates to true --> endless loop. But it
    > was not that obvious to me in the "long" version of the code :)


    s/never evaluates to true/ever evaluates to false/

    Anno
    Anno Siegel, Apr 1, 2005
    #5
  6. Anno Siegel wrote:

    > Kurt <> wrote in comp.lang.perl.misc:
    >
    >
    >>I had a while loop with a counter like this:
    >>
    >>counter = 0;
    >>while ($array[$counter])
    >> {
    >> ...
    >> if (some_statement)
    >> {
    >> ...
    >> $counter++;
    >> }
    >> }
    >>
    >>In this short version of the code it is easy to see what happens if
    >>the "some_statement" never evaluates to true --> endless loop. But it
    >>was not that obvious to me in the "long" version of the code :)

    >
    >
    > s/never evaluates to true/ever evaluates to false/


    Er, no.

    "never evaluates to true for a given value of $counter".

    So long as some_condition() will eventually become true for any value of
    $counter there is no infinite loop.
    Brian McCauley, Apr 1, 2005
    #6
  7. Kurt

    Anno Siegel Guest

    Brian McCauley <> wrote in comp.lang.perl.misc:
    > Anno Siegel wrote:
    > > Kurt <> wrote in comp.lang.perl.misc:
    > >
    > >
    > >>I had a while loop with a counter like this:
    > >>
    > >>counter = 0;
    > >>while ($array[$counter])
    > >> {
    > >> ...
    > >> if (some_statement)
    > >> {
    > >> ...
    > >> $counter++;
    > >> }
    > >> }
    > >>
    > >>In this short version of the code it is easy to see what happens if
    > >>the "some_statement" never evaluates to true --> endless loop. But it
    > >>was not that obvious to me in the "long" version of the code :)

    > >
    > >
    > > s/never evaluates to true/ever evaluates to false/

    >
    > Er, no.
    >
    > "never evaluates to true for a given value of $counter".
    >
    > So long as some_condition() will eventually become true for any value of
    > $counter there is no infinite loop.


    But $counter won't change anymore once some_statement() evaluates to
    false, so it's stuck.

    Anno
    Anno Siegel, Apr 1, 2005
    #7
  8. Anno Siegel wrote:

    > Brian McCauley <> wrote in comp.lang.perl.misc:
    >
    >>
    >>So long as some_condition() will eventually become true for any value of
    >>$counter there is no infinite loop.

    >
    > But $counter won't change anymore once some_statement() evaluates to
    > false, so it's stuck.


    It's amazing how you can tell just form the name that the result of
    some_statement() will not change if $counter does not change.

    Me, I'd need to look at the definition of some_statement().
    Brian McCauley, Apr 1, 2005
    #8
  9. Anno Siegel wrote:

    > Brian McCauley <> wrote in comp.lang.perl.misc:
    >> Anno Siegel wrote:
    >> > Kurt <> wrote in comp.lang.perl.misc:
    >> >
    >> >
    >> >>I had a while loop with a counter like this:
    >> >>
    >> >>counter = 0;
    >> >>while ($array[$counter])
    >> >> {
    >> >> ...
    >> >> if (some_statement)
    >> >> {
    >> >> ...
    >> >> $counter++;
    >> >> }
    >> >> }
    >> >>
    >> >>In this short version of the code it is easy to see what happens if
    >> >>the "some_statement" never evaluates to true --> endless loop. But it
    >> >>was not that obvious to me in the "long" version of the code :)
    >> >
    >> >
    >> > s/never evaluates to true/ever evaluates to false/

    >>
    >> Er, no.
    >>
    >> "never evaluates to true for a given value of $counter".
    >>
    >> So long as some_condition() will eventually become true for any value of
    >> $counter there is no infinite loop.

    >
    > But $counter won't change anymore once some_statement() evaluates to
    > false, so it's stuck.


    You are assuming that once some_statement() evaluates to false, it
    will always evaluate to false on succeeding iterations. I see no
    support for such an assumption.
    >
    > Anno


    --
    Christopher Mattern

    "Which one you figure tracked us?"
    "The ugly one, sir."
    "...Could you be more specific?"
    Chris Mattern, Apr 1, 2005
    #9
  10. Kurt

    Anno Siegel Guest

    Brian McCauley <> wrote in comp.lang.perl.misc:
    > Anno Siegel wrote:
    >
    > > Brian McCauley <> wrote in comp.lang.perl.misc:
    > >
    > >>
    > >>So long as some_condition() will eventually become true for any value of
    > >>$counter there is no infinite loop.

    > >
    > > But $counter won't change anymore once some_statement() evaluates to
    > > false, so it's stuck.

    >
    > It's amazing how you can tell just form the name that the result of
    > some_statement() will not change if $counter does not change.
    >
    > Me, I'd need to look at the definition of some_statement().


    Sure, it could depend on the phase of the moon. I was going on the
    assumption that the pseudo-code showed all relevant actions. Otherwise,
    why show one incrementation of the loop index and not indicate others?

    Anno
    Anno Siegel, Apr 1, 2005
    #10
  11. Kurt

    Joe Smith Guest

    Kurt wrote:

    > while ($array[$counter])
    > {
    > ...
    > if (some_statement)
    > {
    > ...
    > $counter++;
    > }
    > }


    On the other hand, if $counter needs to always be incremented,
    you could re-arrange the loop to:

    while ($counter < @array and $array[$counter]) {
    ...
    next unless some_statement;
    ...
    } continue {
    $counter++;
    }

    -Joe
    Joe Smith, Apr 8, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,501
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,767
  3. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    371
    Ville Mattila
    Jul 24, 2005
  4. pj
    Replies:
    3
    Views:
    274
  5. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    125
    Paul Lalli
    Jan 5, 2005
Loading...

Share This Page