0

I have a CentOS VM on which I'm running a php socket server, that forks on every connection. The child process does its job and then exits.

The parent is also waiting to reap the dead zombie process (I have checked the ps auxf output)

pcntl_wait($status, WNOHANG); is executed after before every fork, so that cleans up 1 Zombie process (if any)

However, after a long run, the parent is unable to fork.

I think this is because of the 32768 limit. The number of process in ps -auxf output are constantly around 750.

[root@test-machine ~]# cat /proc/self/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             119925               119925               processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       119925               119925               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us


[root@test-machine ~]# cat /proc/sys/kernel/pid_max
32768

UPDATE: I checked the logs, and saw the error said PHP Fatal error: Maximum execution time of 30 seconds exceeded in myfile.php

The line it pointed to is the pcntl_wait($status, WNOHANG);, which is for waiting for a child process to terminate. The WNOHANG flag ensures that it does not hang, so if theres no exited child, it will continue the execution.

While the "Max Time" can be changed, something is causing pcntl_wait to loop. I think something on the OS is making this happen. This is the socket that has maximum connections (I have multiple sockets, only this was affected)

Dushyant Bangal
  • 123
  • 1
  • 1
  • 9

1 Answers1

0

I checked PHP documentation for function prcntl_wait and found this:

options

If wait3 is available on your system (mostly BSD-style systems), you can provide the optional options parameter. If this parameter is not provided, wait will be used for the system call. If wait3 is not available, providing a value for options will have no effect. The value of options is the value of zero or more of the following two constants OR'ed together:

May be your OS doesn't have wait3 and this cause that issue. May be you could change function to pcntl_waitpid and this solve your issue.

Alexander Tolkachev
  • 4,608
  • 3
  • 14
  • 23
  • No, if that was the case, the server would have frozen when there was no dead child, like it does when I don't specify `WNOHANG`. The issue I have posted does not happen everytime. It was running fine for 4 days, then it crashed. – Dushyant Bangal Aug 02 '18 at 04:57