From Bugzilla Helper: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; .NET CLR 1.0.3705; .NET CLR 1.1.4322) Description of problem: I notice since RH9, the return value of system() doesn't work correctly. The following code will print out return 0 or -1 randomly, please help me how to solve this problem because I need to check if return value is 0 or -1 to make sure system call is fine or not. It happens since RH9, and it works fine before with all the previous verion RedHat. We use RedHat as platform for our world wide services, and hope this problem in RH9 can't fixed. > #include <signal.h> > > main() > { > struct sigaction v_sig; > > #if !defined(linux) > v_sig.sa_flags = SA_NOCLDWAIT; > #else > v_sig.sa_handler = SIG_IGN; > #endif > > sigaction(SIGCHLD, &v_sig, 0); > > printf("return %d\n", system("ls -l > /dev/null")); > > return (0); > } > Version-Release number of selected component (if applicable): glibc-2.3.2-27.9 How reproducible: Always Steps to Reproduce: 1. Run the example code above 2. and you will see 3. Additional info: gnu guys ask me to ask RedHat first because they don't have control on glibc.
Setting SIGCHLD to SIG_IGN means children will be automatically reapped. This includes the child created in system (3), so if waitpid in system happens to be run when the child is already gone, system will return -1.
The code is to solve the problem of [defunt] because we have a lot of fork in our software, and it works well under previous verion of Red Hat - 6.x, 7.x, 8.0. It only has problem in RH9. Please let me how I can work around this? I need expert advise. Thanks.
There is no way to disable SIGCHLD generation and zombie conversion for some child processes but not others. system creates children using fork just as your program does, so its children are treated the same way. system failing with errno set to ECHILD is correct for this case. If you want children created by system to have their exit status reported by system, you must reset SIGCHLD to other than SIG_IGN before calling system.