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 3934128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:40:49+00:00 2026-05-19T23:40:49+00:00

Well the child process may exit with error but pcntl_wifexited always return true <?php

  • 0

Well the child process may exit with error but pcntl_wifexited always return true

<?php

//Sample code :
$child_pid = pcntl_fork();

if ($child_pid === 0) 
{
    //This is child process

    $my_var = rand(1,5);

    if($my_var == 2)
    {
        //2 is not allowed
        exit(1); //exit with error
    }

    if($my_var == 4)
    {
        //4 is unknown
        i_crash_now(); //crash
    }

    echo 'end of child' . "\n";
    exit(0); //exit standard

}
else
{
    sleep(1); //waiting for child with ninja code (don't do that at home, this was made by professional ninjas)
    pcntl_waitpid($child_pid, $status, WNOHANG);

    var_dump(pcntl_wstopsig($status));  //in case 2 > 1, in case 4 > 255, else 0
    var_dump(pcntl_wifexited($status)); //always true;
}

exit(0);

I may use the signal to find errors, but I don’t get what’s wrong with pcntl_wifexited().

Is this related to WNOHANG option?

  • 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-19T23:40:49+00:00Added an answer on May 19, 2026 at 11:40 pm

    I imagine the pcntl_waitpid behaves similarly to the normal waitpid call.

    WNOHANG forces waitpid to return 0 if no process is terminated [it’s akin to a zero timeout].

    Hence, exit code will appear to be normal.

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

Sidebar

Related Questions

This code works well in Mac/Linux, but not in Windows. import mmap import os
I have tried everything I can think of and every code sample imaginable but
Well... simple question, right? But with no so simple answers. In firefox i use
Well, it seems simple enough, but I can't find a way to add a
well i have this messages table with sample values like these: msg_id recipient_id read
I'm spawning a child process that runs in a visible console window (it's a
I'm trying to create a child process in another process. I am writing both
I'm creating child processes with fork() in C/C++. When the parent process ends (or
Calling fclose() here after dup() ing its file descriptor blocks until the child process
PHP's pcntl_fork function is supposed to fork a process just as the standard fork

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.