简体   繁体   English

进程挂起并且PIPE被阻止

[英]Process hangs and PIPE is blocked

I seem to have a deadlock. 我似乎陷入僵局。 I have perl scripts forking and calling another perl scripts. 我有分叉的perl脚本,并调用了另一个perl脚本。 And the process hangs somewhere. 并且该过程挂在某处。

I am running the program on : Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; 我在以下程序上运行该程序:Darwin Kernel Version 12.3.0:Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64 根目录:xnu-2050.22.13〜1 / RELEASE_X86_64 x86_64

"lsof" has 4 entries referring to the same PIPE: “ lsof”有4个条目引用相同的PIPE:

perl5.12 1414 root 1 PIPE 0x48937dc1254fe937 16384 ->0x48937dc1254fe727 perl5.12 1414根1 PIPE 0x48937dc1254fe937 16384-> 0x48937dc1254fe727

perl5.12 1768 root 1 PIPE 0x48937dc1254fe937 16384 ->0x48937dc1254fe727 perl5.12 1768根1 PIPE 0x48937dc1254fe937 16384-> 0x48937dc1254fe727

perl5.12 1759 root 1 PIPE 0x48937dc1254fe937 16384 ->0x48937dc1254fe727 perl5.12 1759根1 PIPE 0x48937dc1254fe937 16384-> 0x48937dc1254fe727

perl5.12 1760 root 1 PIPE 0x48937dc1254fe937 16384 ->0x48937dc1254fe727 perl5.12 1760根1 PIPE 0x48937dc1254fe937 16384-> 0x48937dc1254fe727

I am suspecting that is the cause of the hang. 我怀疑这是挂起的原因。 Do we have any commands that could tell me which process reading/writing into this PIPE? 我们是否有任何命令可以告诉我哪个进程对该PIPE进行读/写操作? Or any further information would be appreciated. 或任何进一步的信息将不胜感激。 Thanks in advance! 提前致谢!

There's two likely possibilities I can think of: 我可以想到两种可能的可能性:

  1. There's deadlock due to output buffering. 由于输出缓冲而导致死锁。 Try enabling autoflush on all the output pipes. 尝试在所有输出管道上启用自动冲洗。 This is likely if two processes are communicating bidirectionally using pipes: they each write something and wait to read a response, but because the output is buffered the response is never sent to the pipe. 如果两个进程正在使用管道进行双向通信,则有可能发生这种情况:它们每个都写东西并等待读取响应,但是由于缓冲了输出,因此从未将响应发送到管道。

  2. A process is waiting for EOF on the pipe, but it never comes. 进程正在等待管道上的EOF,但从未成功。 If the pipe is created in a parent process and then inherited by a child process, you need to ensure that all the processes close the write end of the pipe so that the reader will read EOF. 如果管道是在父进程中创建的,然后由子进程继承,则需要确保所有进程都关闭管道的写端,以便读取器将读取EOF。

As Barmar also explained the Child Processes can get stuck when the Output Buffer fills up. 正如Barmar还解释的那样,当输出缓冲区填满时,子进程可能会卡住。 In this case you will find the Child Process stuck in the write() Function Call. 在这种情况下,您会发现子进程卡在write()函数调用中。

You will have to use Perl IO::Select Module in the Parent Process to continuesly read the Output Buffer from the Child and thereby empty it if the Output from the Child Process is bigger than the Buffer. 您将不得不在父进程中使用Perl IO::Select模块来继续从子进程读取输出缓冲区,如果子进程的输出大于缓冲区,则将其清空。

The official Perl Documentation at http://perldoc.perl.org/functions/sysread.html explains: http://perldoc.perl.org/functions/sysread.html上的官方Perl文档解释了:

sysread FILEHANDLE,SCALAR,LENGTH sysread FILEHANDLE,SCALAR,LENGTH
Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE, using read(2). 尝试使用read(2)从指定的FILEHANDLE中将LENGTH个字节的数据读取到变量SCALAR中。 It bypasses buffered IO, so mixing this with other kinds of reads, print, write, seek, tell, or eof can cause confusion because the perlio or stdio layers usually buffer data. 它绕过缓冲的IO,因此将其与其他类型的读取,打印,写入,查找,告知或eof混合会引起混淆,因为Perlio或stdio层通常会缓冲数据。

Further to see the System Activity I usually use the strace Command which nicely shows how each process reads and writes data. 为了进一步了解系统活动,我通常使用strace命令,该命令很好地显示了每个进程如何读取和写入数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM