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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 + 37 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 25 01:01:30 2024 UTC