php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39972 pcntl_signal not working
Submitted: 2006-12-28 05:27 UTC Modified: 2006-12-28 17:34 UTC
From: kementeus at gmail dot com Assigned:
Status: Not a bug Package: PCNTL related
PHP Version: 5.2.0 OS: Debian 3.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kementeus at gmail dot com
New email:
PHP Version: OS:

 

 [2006-12-28 05:27 UTC] kementeus at gmail dot com
Description:
------------
pcntl_signal is not executing the code inside the function handling of the signal. The code example is taken from the php manual in http://www.php.net/manual/en/ref.pcntl.php and modified just to echo a simple text

Reproduce code:
---------------
<?php
declare(ticks=1);

$pid = pcntl_fork();
if ($pid == -1) {
     die("could not fork"); 
} else if ($pid) {
     exit(); // we are the parent 
} else {
     // we are the child
}

if (!posix_setsid()) {
   die("could not detach from terminal");
}

while (1) {
   // do something interesting here
}

function sig_handler($signo) 
{
     switch ($signo) {
         case SIGTERM:
             // handle shutdown tasks
             echo "I need to execute\n";
             exit;
             break;
         case SIGHUP:
             // handle restart tasks
             break;
         default:
             // handle all other signals
     }

}

// setup signal handlers
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
?> 

Expected result:
----------------
When you send the signal SIGTERM with kill -15 PID the process should echo the message "I need to execute" and then terminate.

Actual result:
--------------
The process terminate but doesn't echo or execute anything inside the function handler.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-28 10:00 UTC] tony2001@php.net
Move pcntl_signal() somewhere BEFORE endless loop, so it gets called after all.
 [2006-12-28 17:24 UTC] kementeus at gmail dot com
Fixed when moving the pcntl_signal before the loop, now submitting the fixing in the documentation
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 05:01:26 2024 UTC