Skip to content

Commit

Permalink
Resolve issue #14
Browse files Browse the repository at this point in the history
Child processes now check the pid of their parent process. If this changes or is 1 the parent proces is dead and the child processes will exit
  • Loading branch information
nook24 committed Jan 12, 2016
1 parent 52c9e39 commit 7cff7c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cakephp/app/Console/Command/StatusengineLegacyShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public function main(){
$this->config_type = Configure::read('config_type');

$this->Logfile->init(Configure::read('logfile'));
$this->parentPid = getmypid();
$this->Logfile->welcome();
$this->parser = $this->getOptionParser();
$this->out('Starting Statusengine version: '.Configure::read('version').'...');
Expand Down Expand Up @@ -2756,6 +2757,11 @@ public function waitForInstructions(){

}
pcntl_signal_dispatch();
//Check if the parent process still exists
if($this->parentPid != posix_getppid()){
$this->Logfile->clog('My parent process is gone I guess I am orphaned and will exit now!');
exit(3);
}
usleep(250000);
}
}
Expand All @@ -2778,6 +2784,12 @@ public function childWork(){
if($this->worker->returnCode() == GEARMAN_NO_ACTIVE_FDS){
sleep(1);
}

//Check if the parent process still exists
if($this->parentPid != posix_getppid()){
$this->Logfile->clog('My parent process is gone I guess I am orphaned and will exit now!');
exit(3);
}
}
}
}
Expand Down

0 comments on commit 7cff7c0

Please sign in to comment.