这是我的代码(这只是一个例子)
int a = system("pwd");
printf("pwd with return: %d\n", a);
cout << "errno is " << errno << "\n";
signal(SIGCHLD, SIG_IGN);
a = system("pwd");
printf("pwd with return: %d\n", a);
cout << "errno is " << errno << "\n";
我只是在“SIGCHLD”之前和之后使用系统调用运行“pwd”命令,我得到了两个不同的结果:
<actual path>
pwd with return: 0
errno is 0
<actual path>
pwd with return: -1
errno is 10
在这两种情况下,命令都会正确执行。
为什么signal(SIGCHLD, SIG_IGN);
会产生这个问题?有没有办法避免它?