管道阻塞与关闭

  • close FILEHANDLE

  • close

    Closes the file or pipe associated with the filehandle, flushes the IO buffers, and closes the system file descriptor. Returns true if those operations succeed and if no error was reported by any PerlIO layer. Closes the currently selected filehandle if the argument is omitted.

    You don't have to close FILEHANDLE if you are immediately going to do another open on it, because opencloses it for you. (See open.) However, an explicit close on an input file resets the line counter ($. ), while the implicit close done by open does not.

    If the filehandle came from a piped open, close returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero, $! will be set to 0 . Closing a pipe also waits for the process executing on the pipe to exit--in case you wish to look at the output of the pipe afterwards--and implicitly puts the exit status value of that command into $? and${^CHILD_ERROR_NATIVE} .

    If there are multiple threads running, close on a filehandle from a piped open returns true without waiting for the child process to terminate, if the filehandle is still open in another thread.

    Closing the read end of a pipe before the process writing to it at the other end is done writing results in the writer receiving a SIGPIPE. If the other end can't handle that, be sure to read all the data before closing the pipe.

    Example:

       
       
    1. open(OUTPUT, '|sort >foo') # pipe to sort
    2. or die "Can't start sort: $!";
    3. #... # print stuff to output
    4. close OUTPUT # wait for sort to finish
    5. or warn $! ? "Error closing sort pipe: $!"
    6. : "Exit status $? from sort";
    7. open(INPUT, 'foo') # get sort's results
    8. or die "Can't open 'foo' for input: $!";

    FILEHANDLE may be an expression whose value can be used as an indirect filehandle, usually the real filehandle name or an autovivified handle.


    管道关闭前会发送给调用的命令一个管道关闭信号,上一级收到这个信号一般会死掉,管道会等上级死掉后关闭。

    如果在自己脚本加上 pipe ignore 则 管道发送的关闭信号无效,管道会等待上级运行完毕才关闭。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值