c - exit status of a program running in background

后端 未结 1 2008
故里飘歌
故里飘歌 2021-01-21 15:25

I have an assignment in which I have to create a mini shell which is capable of doing a lot of things including job control. I managed to create new jobs using fork and execvp.

相关标签:
1条回答
  • 2021-01-21 16:01

    If you don't do anything special the parent receives a SIGCHLD when the child dies. Careful though, multiple children can terminate at the same time and you'll get a single signal. The correct way to handle this is to loop (in the signal handler):

    while (waitpid(-1, NULL, WNOHANG) > 0)
        /* Stuff. */
    
    0 讨论(0)
提交回复
热议问题