Jump to content

SIGINT not being caught


Sonzai

Recommended Posts

Hi guys,

 

  Like the title says, for some reason SIGINT is not being caught and ending the process when it is sent.

<?php

 define('logdir', '/var/www/html/Project2');

 $pid = getmypid();
 function catch_sigint($sig_num) {

   print('got a signal sigint\n');
   flush(STDOUT);

     pcntl_signal(SIGINT, "catch_sigint");
     posix_kill($pid, SIGINT);
     exit(1);

 }

  if((count($argc) < 1 )||(count($argc) >=2)) {
    print("usage: webserver idcode");
    exit(1);
  }

  pcntl_signal(SIGINT, "catch_sigint");

  while(1) { print "running"; sleep(3); }

?>

If it's any insight, I had an interesting problem with getting the pid - I originally tried posix_getpid() but it gave an error saying that it was undefined though I'm running this on a Linux machine. The webserver env. is Apache. Thanks for any and all help!

 

Link to comment
https://forums.phpfreaks.com/topic/282895-sigint-not-being-caught/
Share on other sites

As of PHP 4.3.0 PCNTL uses ticks as the signal handle callback mechanism, which is much faster than the previous mechanism. This change follows the same semantics as using "user ticks". You must use the declare() statement to specify the locations in your program where callbacks are allowed to occur for the signal handler to function properly (as used in the above example).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.