ahuang14 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Do Perl programs automatically time out in a certain amount of time? I set it to parse a tailing file I captured with Snort but it stopped last night and I am not sure why. The Snort program is still running and capturing as we speak but the Perl program seemed to stop after about 30 minutes. I started it at 4:30 and it stopped at 5:03. I wanted it to parse everything overnight. Is there an explanation for this? I could show you the code but there is nothing in it to suggest a time out. I have a loop running:

while(defined ($line = $file -> read)){ ... }

so this should be running as long as new stuff comes in. Any help?

Replies are listed 'Best First'.
Re: Do Perl Programs Timeout on Their Own
by JavaFan (Canon) on Jul 21, 2011 at 12:47 UTC
    Do Perl programs automatically time out in a certain amount of time?
    No.

    But it may be stuck in a blocking I/O call, running an infinite loop, stopped after receiving SIGSTOP, or sleeping. Depending on your OS, you may (or may not) have tools available to see what a running program is doing.

      There has been a new entry in the Snort file about every minute basically and maybe not so much over night when no one is at work, but definitely more often after it timed out at least until around 6 or 7. I didn't have a SIGSTOP and I dont know if it slept by itself. I actually do want it to run an infinite loop basically so that it will run as long as a new entry comes into the program. Maybe I should just try putting it all in an explicit infinite loop of like x=1 to see if that works.

        Difficult to guess without much code, but did you consider the case that your perl couldn't read anymore from the file and happily left the loop you have programmed? Perl jumps out the loop if the result is undef in your statement.

        This is possible in different cases. For example if Perl is much faster then 'Snort' and 'Snort' is blocking the file while writing. Or you log is somewhere rotated by a deamon on your system and the file doesn't exists anymore as happens on any Linux system?

        Catching errors and couple print statements to a small log file can give you a clue where and when your perl program quited.

        For such cases (waiting for another program to append a file) i think it is better to not let the file handle the whole time open. Open the file, read everything till the EOF, sleep and restart. Use a variable to keep the track of the position in the log, for example via a time stamp in the log. Seek to the last position and start from there.

        Regards

        Martell

Re: Do Perl Programs Timeout on Their Own
by DStaal (Chaplain) on Jul 21, 2011 at 12:50 UTC

    Did you run this from a terminal, in the foreground? Perl programs themselves don't time out, but if they are run from a terminal and the terminal times out, the OS will kill the foreground process.

      I ran it on Windows in a command prompt but it never timed out.

        Your program needs to maintain some kind of a log.   In addition, you should examine the Windows event-log viewer to see if any application-related messages are in there.   When a program crashes, it’s usually recorded.