Zombie Threads on POSIX systems

前端 未结 2 1609
抹茶落季
抹茶落季 2021-01-13 10:34

How do zombie threads get formed in C/C++, and what do you need to make sure to do in order to prevent them from being created? I know they\'re just normal threads that did

2条回答
  •  广开言路
    2021-01-13 11:15

    Do you mean pthreads or zombie processes? A zombie process (not thread) gets created when a parent doesn't reap its child. It's because the OS keeps the return state of the process if the parent needs it later. If the parent dies, the child is given to the init thread which just sits and calls "wait" over and over again (reaping any children that die). So a zombie process can only be created when the parent is still alive and the child has terminated.

    The same applies for pthreads. If you detach the thread, it will not keep that process termination state around after it finishes (similar to processes).

提交回复
热议问题