Here is an example piece of my code
signal(SIGCHLD, SIG_IGN);
ret = system("ls -al");
if(ret < 0)
{
perror("system failed");
printf("return value is %d
", ret);
}
The ls -al
command can be executed without any problem.
But the return value of system()
is always -1. In this case, I can't get the real return value of the command.
Some reference says that ignore SIGCHLD would affect waitpid()
in system()
, that's why system
always returns -1.
But what puzzles me more is that: isn't SIGCHLD ignored by default? So why ignoring SIGCHLD explicitly would result in such case?
Could someone explain this to me?
Thanks to @cnicutar now I understand the effects of ignoring SIGCHLD.
But now I'm wondering is there any methods to get the return value of child process while SIGCHLD is ignored? Or is this just impossible due to the POSIX specification and OS realizaiton?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…