Perl script hangs

K

Kurt

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
 
P

Peter Wyzl

: 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
 
P

phaylon

Kurt said:
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
 
K

Kurt

Kurt said:
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
 
A

Anno Siegel

Kurt said:
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
 
B

Brian McCauley

Anno said:
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.
 
A

Anno Siegel

Brian McCauley said:
Anno said:
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
 
B

Brian McCauley

Anno said:
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().
 
C

Chris Mattern

Anno said:
Brian McCauley said:
Anno said:
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.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
A

Anno Siegel

Brian McCauley said:
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
 
J

Joe Smith

Kurt said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top