tcsh 關閉文件描述符

tcsh 關閉文件描述符

我有一個使用 tcsh 腳本啟動的程式。我想透過管道與該進程進行通訊(不是命名管道)由父進程建立。但是,看起來 tcsh 會關閉每個開啟的管道(0-2啟動時除外)。

範例(可能比需要的稍長,問題一旦出現就可見B''):

為了“清晰”,我將用 來標識 bash 提示$,用 來標識 tcsh 提示%。當進程是分叉時,我會增加該字母,並添加'來標記呼叫exec (3)

A$ exec 42>42_output.txt # open fd 42
A$ ls /proc/$$/fd
0  1  2  255  3  42
A$ bash # launch bash as a child
B$ echo test >&42 #writes "test" to the file
B$ exec bash
B'$ echo test2 >&42 # also writes to the file
B'$ ls /proc/$$/fd
0  1  2  255  3  42
B'$ tcsh
B''% ls /proc/$$/fd
0  1  15  16  17  18  19  2
B''% bash
C$ ls /proc/$$/fd
0  1  2  255  3
C$ exit
B''% exec bash
B'''$ ls /proc/$$/fd
0  1  2  255  3
A$ exit
A$ ls /proc/$$/fd
0  1  2  255  3  42
A$ exec tcsh
A$ ls /proc/$$/fd
0  1  15  16  17  18  19  2  4

檔案描述符已關閉,這意味著我無法再從子進程中使用它。有什麼方法可以告訴 csh 保留(避免關閉)檔案描述符嗎?

相關內容