Terminating zombie child processes forked from socket server

后端 未结 4 2045
攒了一身酷
攒了一身酷 2021-02-05 10:37

Disclaimer

I am well aware that PHP might not have been the best choice in this case for a socket server. Please refrain from suggesting differen

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 11:15

    Regards your disclaimer - PHP is no better / worse than many other languages for writing a server in. There are some things which are not possible to do (lightweight processes, asynchronuos I/O) but these do not really apply to a forking server. If you're using OO code, then do ensure that you've got the circular reference checking garbage collector enabled.

    Once a child process exits, it becomes a zombie until the parent process cleans it up. Your code seems to send a KILL signal to every child on receipt of any signal. It won't clean up the process entries. It will terminate processes which have not called exit. To get the child process reaped correctly you should call waitpid (see also this example on the pcntl_wait manual page).

提交回复
热议问题