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

Hi All,
Ive a perl script which is multi process for processing some files. A short algorithm of the script is as follows

1. it forks child processes and divides equally all the text files among them.
2. child processes read the text files and <do something> in a loop which terminates at eof.
3. After processing each file it archives the file by compressing and moving to new location.
4. Now after all the files are processed, the process processing the last file hangs after 2nd Step in 3rd step. (we know this via logging mechanism im using)


Output of pstack for the process 1988(pid of the one of the child proc +ess that hanged) pstack 1988 #1 0x000000317d8f0990 in PerlIOUnix_read () from /usr/lib64/perl5/5.8 +.8/x86_64-linux-thread-multi/CORE/libperl.so #2 0x000000317d8f5055 in PerlIOBuf_fill () from /usr/lib64/perl5/5.8. +8/x86_64-linux-thread-multi/CORE/libperl.so #3 0x000000317d8ef8c8 in Perl_PerlIO_fill () from /usr/lib64/perl5/5. +8.8/x86_64-linux-thread-multi/CORE/libperl.so #4 0x000000317d8f4cbf in PerlIOBase_read () from /usr/lib64/perl5/5.8 +.8/x86_64-linux-thread-multi/CORE/libperl.so #5 0x000000317d8f4dfb in PerlIO_getc () from /usr/lib64/perl5/5.8.8/x +86_64-linux-thread-multi/CORE/libperl.so #6 0x000000317d8a2a20 in Perl_sv_gets () from /usr/lib64/perl5/5.8.8/ +x86_64-linux-thread-multi/CORE/libperl.so #7 0x000000317d88db93 in Perl_do_readline () from /usr/lib64/perl5/5. +8.8/x86_64-linux-thread-multi/CORE/libperl.so #8 0x000000317d88a33e in Perl_runops_standard () from /usr/lib64/perl +5/5.8.8/x86_64-linux-thread-multi/CORE/libperl.so #9 0x000000317d837e9c in perl_run () from /usr/lib64/perl5/5.8.8/x86_ +64-linux-thread-multi/CORE/libperl.so #10 0x000000000040179c in main ()

This is my issue. In case nyone need more info plz lemme know.

Thanks
AvantA

Replies are listed 'Best First'.
Re: perl process hangs after processing the last file.
by cdarke (Prior) on Jan 18, 2011 at 12:50 UTC
    Difficult (impossible?) to say without seeing your code. A typical cause of a hang might be waiting for a pipe to be closed by the writer or waiting on a signal.

    You could try to use strace on the hanging process (strace -p pid) which could give you an idea.

    we know this via logging mechanism
    be careful, the log file might not be up-to-date if some records are waiting in a buffer. Check by switching off buffering if you can.
      Hi cdarke, I cannot paste the code as its confidential. btw strace info is as follows:
      strace -fe verbose=all -p 19881 Process 19881 attached - interrupt to quit read(7, ls -l /proc/19881/fd/ total 0 lr-x------ 1 root root 64 Jan 17 20:02 0 -> pipe:[1771023532] l-wx------ 1 root root 64 Jan 17 20:02 1 -> pipe:[1771023666] l-wx------ 1 root root 64 Jan 17 20:02 2 -> pipe:[1771023533] lrwx------ 1 root root 64 Jan 17 20:02 3 -> socket:[1771025115] lr-x------ 1 root root 64 Jan 17 20:02 4 -> /opt/opwv/OKRAuser/3.1.1/E +TL/data/input/rba/abc.log.working lrwx------ 1 root root 64 Jan 17 20:02 7 -> socket:[1771023680]

      Thanks
      AvantA
        OK, so it is reading file descriptor 7, which is a socket. So you need to look at your closedown sequence. How does the writer indicate that there is no further data? Does the reader check for this correctly?
Re: perl process hangs after processing the last file.
by jethro (Monsignor) on Jan 18, 2011 at 14:21 UTC

    What happens if you process only one file? Or no files? This might give you some hints (especially if the no-files case hangs too)

      hi jethro,
      For no files or single file this doesnt hang. but if there are lots of file then this issue is reproduced.

      Thanks
      AvantA