0

Have some code like this:

unsigned pid = waitpid(mPid, &status, WNOHANG);
mExitStatus = WEXITSTATUS(status);

Get the debug print for the variable like:

mExitStatus = 15
status = 3840

For "mExitStatus = WEXITSTATUS(status)", I got following statment which explains

evaluates to the least significant eight bits of the return code of the child which terminated
3840 = F00; F is 15 which is assigned to mExitStatus

But question is how I can use this 15 to judge whether if the child process is terminated correctly or not?

15 is from 3840. But 3840 is return by linux process? Any meaning for that?

In a general description, my main started 4 child_process running 4 tests. I would like to judge in my main if those 4 tests are passed or not. So I think I need to jude on the exit status of my child process.

Thanks

thundium
  • 995
  • 4
  • 12
  • 30
  • Remember that the "exit status" of a process is what the process `main` function returns or the value passed to the `exit` function. How to interpret it up to you, but traditionally zero is used for "okay" and any non-zero value is for "not okay". – Some programmer dude May 18 '14 at 08:51
  • @JoachimPileborg So it is my code somewhere(I got the code package from someone else)which decides the value 3840? – thundium May 18 '14 at 08:56
  • No, only the eight low bits is decided by the child-process, the value `15`. The other bits are set by the system. Read e.g. the [`waitpid`](http://man7.org/linux/man-pages/man2/waitpid.2.html) manual page for more information. – Some programmer dude May 18 '14 at 09:17

1 Answers1

1

The standard is that an exit status of zero means "success" and anything else is some sort of failure. On *nix systems, a value from 129 to 150 or so can usually be interpreted as "the process was terminated due to a signal" and the signal number is the return value minus 128. A generic failure often returns 1, but sometimes 2 or 3 or some other small number.

In the end, what a program returns is completely up to the program, but those are the typical values.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436