http://www.perlmonks.org?node_id=1019501


in reply to Re^2: print() function hang for long time
in thread print() function hang for long time

Hi dengguochen2003

Read Suffering from Buffering to know more about buffering.

  • Comment on Re^3: print() function hang for long time

Replies are listed 'Best First'.
Re^4: print() function hang for long time
by dengguochen2003 (Initiate) on Feb 22, 2013 at 06:33 UTC
    Hi, everybody, thank you for your attention on this problem. Finally I got the root cause. The reason is that the Linux kernel is configure to use console as standard output. And at the time when the perl is running the serial port is stuck. So the perl script hangs.
Re^4: print() function hang for long time
by dengguochen2003 (Initiate) on Feb 19, 2013 at 13:32 UTC
    Hi, vinoth.ree, soonix, thank you for pointing out the perl buffer. While this issue might not apply. I execute this script on various machines and it always goes ok. Only on this IBM machine with TTY console configured this problem shows up. So I am confused a lot. What is more, the script resumes when I login console and hit "return" next day.

      Perhaps just on this machine, perl is configured differently (e.g. bigger buffers), or the operating system might add another level of buffers ...

      "rc3" sounds like an init script, that would log to a file, wouldn't it? So that is usually buffered.

      Most probably your login triggers other activities that make your "rc3" print additional messages, thus filling the buffer and writing it out to disk, and then your tty can see it.

      (This section edited) In my previous msg I overlooked that you print also to a file handle and not only to STDOUT.
      Put the $|=1; statement right after the "hanging" print statement, better yet, put it after both print statements in line 12 and 15, and give it a try.

Re^4: print() function hang for long time
by dengguochen2003 (Initiate) on Feb 20, 2013 at 01:53 UTC
    Hi, soonix, thanks for monitoring this issue. Will have a try on your idea. One question is whether the buffer can stuck the process. From the time stamp the process hangs on the print() line for more than 20 hours because code line 23 is executed on 2/15 and gives below time stamp in log line 21(2013/02/15 12:33:27).

    2013/02/15 12:33:27 2013/02/14 16:50:12:Audit:event(2)::SYSTEM