我有一个 C 程序,它使用 forkpty 来执行 bash shell。我发现此 shell 启动的程序在启动时忽略了 SIGINT,因此当我向 shell 发送 Ctrl-C 时,它们永远不会关闭。
例子:
int masterFd;
char* args[] = {"/bin/bash", "-i", NULL };
int procId = forkpty(&masterFd, NULL, NULL, NULL);
if( procId == 0 ){
execve( args[0], args, NULL);
}
else {
// Simple code that reads from standard in and writes to masterFd.
// I also register for Ctrl-C and write it to masterFd if caught
}
Run Code Online (Sandbox Code Playgroud)
其他控制字符似乎可以通过,ctrl-D,ctrl-?然而,每当我查看新 bash shell 启动的进程的状态时,它看起来好像 SIGINT 被屏蔽了。
MyShell:# sleep 1000
StandardTerm:# ps …Run Code Online (Sandbox Code Playgroud)