Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:24:27+00:00 2026-06-02T20:24:27+00:00

According to the PHP docs for pcntl_wait , The wait function suspends execution of

  • 0

According to the PHP docs for pcntl_wait,

The wait function suspends execution of the current process until a child has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function.

However, when I run the following code and send SIGTERM to the parent process with kill -s SIGTERM [pid] the signal handler is only called after the child exits (i.e. I have to wait for the sleep to finish. Shouldn’t pcntl_wait() be interrupted by SIGTERM?

fork_test.php:

<?php
  declare(ticks = 1);

  function sig_handler($signo) {
    switch ($signo) {
      case SIGTERM:
        echo 'SIGTERM' . PHP_EOL;
        break;
      default:
    }
  }

  pcntl_signal(SIGTERM, 'sig_handler');

  $pid = pcntl_fork();

  if ($pid == -1) {
     die('could not fork');
  }
  else if ($pid) {
    echo 'parent' . PHP_EOL;

    pcntl_wait($status);
  }
  else {
    echo 'child' . PHP_EOL;
    sleep(30);
  }
?>

Output (SIGTERM only appears after waiting 30 seconds):

$ php fork_test.php
child
parent
SIGTERM

PHP Version => 5.3.3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:24:28+00:00Added an answer on June 2, 2026 at 8:24 pm

    Your call to pcntl_signal specifies that the call should be restarted. Check the docs, restart_syscalls is true by default. So your call to pcntl_signal doesn’t return until the child has terminated.

    You have no call to flush. So PHP can hold the output of echo in a buffer.

    So the behavior you are seeing is precisely the behavior you are requesting. The system call is restarted and the output is buffered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to PHP's official documentation the imagepng() function has the following signature: bool imagepng
According to http://www.codeguru.com/forum/showthread.php?t=463663 , C#'s getHashCode function in 3.5 is implemented as: public override
According to the PHP docs, one can initialize properties in classes with the following
For personal use I am currently writing a recursive PHP function that should process
According to PHP, locale information is maintained per process. Is my understanding correct that
According to the PHP documentation: The overload() function will enable property and method call
According to php manual nor php://input neither $HTTP_RAW_POST_DATA work with multipart/form-data POST-requests. php://input allows
According to the PHP manual , a class like this: abstract class Example {}
I would like to change this: // use appropiate lang.xx.php file according to the
According to the PDO documentation , you can store database login details in php.ini,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.