Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl多管CLOEXEC_Perl_Fork_Pipe_File Descriptor - Fatal编程技术网

perl多管CLOEXEC

perl多管CLOEXEC,perl,fork,pipe,file-descriptor,Perl,Fork,Pipe,File Descriptor,我试图在perl中为同一分叉进程设置多个管道。这是一个只有一个的最小示例,但最后我希望以这种方式拥有多个管道: #!/usr/bin/perl use Fcntl; pipe PIPEREAD, PIPEWRITE; # is supposed to increase the max file descriptors $^F = 255; # default is 2 $flags = fcntl(PIPEREAD, F_GETFL, 0); # doesn't do anything

我试图在perl中为同一分叉进程设置多个管道。这是一个只有一个的最小示例,但最后我希望以这种方式拥有多个管道:

#!/usr/bin/perl

use Fcntl;

pipe PIPEREAD, PIPEWRITE;

# is supposed to increase the max file descriptors
$^F = 255; # default is 2

$flags = fcntl(PIPEREAD, F_GETFL, 0);
# doesn't do anything 
fcntl(PIPEREAD, F_SETFL, $flags & (~FD_CLOEXEC)) or die "Can't set flags: $!\n";

if (!fork()) {
    exec("cat", "/dev/fd/" . fileno(PIPEREAD));
}

print PIPEWRITE "Test\n";
close PIPEWRITE;

sleep(1);
这会失败,因为在调用exec时,
2
上面的所有文件描述符都已关闭。我如何防止这种行为

失败于

cat: /dev/fd/3: No such file or directory
我已尝试取消设置
FD\u CLOEXEC
标志并增加
$^F
。什么都不管用。

在perlvar(1)中,它说:

文件描述符的执行关闭状态将根据相应文件、管道或套接字打开时的$^F值而不是“exec()”的时间来决定

因此,将
$^F=255
移动到
管道之前,它应该可以工作。

在perlvar(1)中,它说:

文件描述符的执行关闭状态将根据相应文件、管道或套接字打开时的$^F值而不是“exec()”的时间来决定


因此,将
$^F=255
移动到
管道之前,它应该可以工作。

CLOEXEC
在管道打开时设置正确,因此在运行
管道之前必须设置
$^F
。如果您切换该顺序,即使不使用
fcntl
,对我来说也可以


此外,如果要使用
fcntl
设置它,则需要使用
F_SETFD
,而不是
F_SETFL
CLOEXEC
在管道打开时设置正确,因此在运行
管道之前必须设置
$^F
。如果您切换该顺序,即使不使用
fcntl
,对我来说也可以

此外,如果要使用
fcntl
进行设置,则需要使用
F_SETFD
,而不是
F_SETFL