C++: system(0) Returns 0

后端 未结 2 670
庸人自扰
庸人自扰 2020-12-20 03:52

When I call system(0) it returns 0, which means shell is not available.

When a command using system (calls gcc to compile a hello world pr

2条回答
  •  执念已碎
    2020-12-20 04:27

    This could happen if you are ignoring the SIGCHLD signal using code like :

    signal(SIGCHLD, SIG_IGN);
    

    This would cause system to return -1 when all children have ended, setting errno to ECHILD.

    Refer to http://pubs.opengroup.org/onlinepubs/009695399/functions/wait.html. Specifically :

    If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, and the process has no unwaited-for children that were transformed into zombie processes, the calling thread shall block until all of the children of the process containing the calling thread terminate, and wait() and waitpid() shall fail and set errno to [ECHILD].

提交回复
热议问题