Lemme begins by describing the basic description of the code that I have. I start with the main parent process (NOTE: I do not show all the functions for simplicity. Let me know if you need me to expand at any time):
declare(ticks=1); pcntl_signal(SIGHUP, array('forker', 'restartSignalHandler')); if(forker_is_not_running()){ new Forker(); } class Forker { private $active_forks = array(); private $parent_pid = null; public function __construct(){ $this->parent_pid = getmypid(); $this->create_fork(); $this->wait_for_active(); } public function wait_for_active(){ while(!empty($this->active_forks)){ foreach($this->active_forks as $k=>$fork){ if($this->fork_no_longer_running($fork)){ unset($this->active_forks[$k]); } } } }
Here's what happens:
- I run my script and correctly get processes (e.g. Parentpid: 2, childpid: 3)
- Then I send the parent signal SIGHUP and it correctly kills and starts a new child process (e.g. Parentpid: 2, childpid: 4)
- Then I send the second signal SIGHUP to the parent signal, and it tries correctly and adds a new child process, but it refuses to kill the second childpid. (e.g. Parentpid: 2, undyingchildpid: 4, newchildpid: 5)
Lemme knows if this requires more details / does not make sense. I canβt understand why the first time he will kill children correctly, but the second time itβs not.
The even part of WEIRDER is that when I change it so that I change my reboot handler so that it continues to try to kill the child with SIGINT, it fails every time, but when I send it the SIGKILL command, it kills the child process:
if($time_passed > 60){ posix_kill($pid, SIGKILL); }
I need a child so that it can be killed by SIGINT in order to properly handle it. I don't want just SIGKILL. Is there a reason why the 2nd time around SIGINT will not work, but SIGKILL will?
php subprocess kill-process fork pcntl
Aram papazian
source share