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

  • Home
  • SEARCH
  • 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 294193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:20:40+00:00 2026-05-12T06:20:40+00:00

I have a problem, I use pcntl_fork to fork a process in PHP, $pid

  • 0

I have a problem, I use pcntl_fork to fork a process in PHP,

$pid = pcntl_fork();
if ($pid == -1) {
 die('could not fork');
} else if ($pid) {
 // we are the parent
 pcntl_wait($status); //Protect against Zombie children
} else {
 pcntl_exec("/path/to/php/script");
 echo "Could not Execute...";
}

I am trying to figure out a way to monitor the status of the PHP script executed as the Child in the parent fork. Is there any way we can know if the child is still running or if there was any fatal errors raised during the execution of the child script and to catch all the messages from the child to parent process using;

pcntl_signal(SIGUSR1, "signal_handler");

Thanks & Regards,
Arun Shanker Prasad.

  • 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-05-12T06:20:41+00:00Added an answer on May 12, 2026 at 6:20 am

    You can definitely monitor the child process:

    $pid = pcntl_fork();
    if ($pid == -1) {
     die('could not fork');
    } else if ($pid) {
     // we are the parent
     pcntl_waitpid($pid, $status, WUNTRACED); //Protect against Zombie children
     if (pcntl_wifexited($status)) {
       echo "Child exited normally";
     } else if (pcntl_wifstopped($status)) {
       echo "Signal: ", pcntl_wstopsig($status), " caused this child to stop.";
     } else if (pcntl_wifsignaled($status)) {
       echo "Signal: ",pcntl_wtermsig($status)," caused this child to exit with return code: ", pcntl_wexitstatus($status);
     }
    } else {
     pcntl_exec("/path/to/php/script");
     echo "Could not Execute...";
    }
    
    • pcntl_wifexited() – Checks if status code represents a normal exit
    • pcntl_wifstopped() – Checks whether the child process is currently stopped
    • pcntl_wifsignaled() – Checks whether the status code represents a termination due to a signal
    • pcntl_wexitstatus() – Returns the return code of a terminated child
    • pcntl_wtermsig() – Returns the signal which caused the child to terminate
    • pcntl_wstopsig() – Returns the signal which caused the child to stop

    EDIT:

    To clarify regarding messaging between parent and child process; you definitely cannot catch Exceptions across processes. As far as messaging, using only the PCNTL library you are also limited to process signals and exit codes.

    Not knowing what, exactly, you are doing. You have a variety of other options. I’d suggest one of the following asynchronous messaging solutions, as they could possibly cover your needs.

    File based

    Your child processes could write messages to a file, which would be polled by the parent.

    Memcache based

    Same as above, but using memcached as the communications medium.

    Database based

    Same as above, but using a db table as the communications medium.

    PHP’s semaphore/IPC library

    https://www.php.net/manual/en/book.sem.php

    This allows you to use methods like msg_send() and msg_receive() to communicate across processes.

    I’m confident one of these will provide the solution you are looking for. Going into the specifics of how to use any of these methods, is probably beyond the scope of this question though, but feel free to ask a new question if you need help with whichever method you choose to utilize.

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

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To force a preview means the users are forced to… May 12, 2026 at 2:26 pm
  • Editorial Team
    Editorial Team added an answer Simply do something like this: (nothing to do with CSS)… May 12, 2026 at 2:26 pm
  • Editorial Team
    Editorial Team added an answer The reason for the crash when accessing SelectedColor.CGColor could be… May 12, 2026 at 2:26 pm

Related Questions

i have a problem.. I use the autocomplete plugin, that i edite for make
I have a problem. I use this code: $( '#wall_msg').clone( true ).insertAfter( '#wall_msg' );
I have a problem with ViewHolder class. I use ViewHolder to improve my List
I have a problem with using the prefix, seems like whenever I use the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.