调试我的应用程序我发现shell解释器的奇怪行为(Solaris上的/ bin / sh,Debian中的/ bin / dash)。虽然由shell关闭了shell文件描述符中的fork()数字19(dec)。在我的情况下,它会导致进程之间关闭通信套接字对。
为简洁起见:
/* used for input and output of shell */
#define INIO 19
和
if (input > 0) {
Ldup(input, INIO);
input = INIO;
}
...
static void
Ldup(int fa, int fb)
{
if (fa >= 0) {
if (fa != fb) {
close(fb);
fcntl(fa, 0, fb); /* normal dup */
close(fa);
}
fcntl(fb, 2, 1); /* autoclose for fb */
}
}
所以netto只是关闭FD号码INIO(19);
简单的复制测试:
$ exec 19>&1
$ echo aaa >&19
aaa
$ bash -c 'echo aaa >&19'
aaa
$ dash -c 'echo aaa >&19'
dash: 1: Syntax error: Bad fd number
$ ksh -c 'echo aaa >&19'
aaa
问题是: