I get wrong exit code from waitpid and I can't figure out why. Could someone give me some ideas?
Here what I do:
open2waitpid$?It always returns with -1 no mater what I return from child process. I check with VS debugger that my program returns an exit code of 0. VS says something like this:
The program '[3256] Test.exe: Native' has exited with code 0 (0x0).
I made sure that pids match.
Any ideas?
I just figured it out. waitpid has 3 stages:
1. process is running: waitpid returns 0; $? is -1
2. process is exiting: waitpid returns pid; $? is actual exit code
3. process doesn't exist: waitpid returns -1; $? is -1
so when doing something like while(waitpid($pid, WNOHANG) >= 0) exit code must be retrieved once cycle before that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With