0

I can just speak a little English so I hope you can understand what I said.

I fork a child process , then I do ADD in child process. EX: 56+48=104

If the value lower than 255 , I can use "wexitstatus(status)" to get the answer.

But if the value higher than 256, it would be wrong !

How can I do?

1 Answers1

1

If the program returns an exit code > 255, the program is simply wrong and needs to be fixed. That's against Unix standard. If you're not using standard Unix, you're probably going to need specialist help from within your organisation contacts.

From manpage for wait():

WEXITSTATUS(stat_val)

If the value of WIFEXITED(stat_val) is non-zero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().

It's limited to 8-bits, which means 1 byte, which means the int from WEXITSTATUS can only range from 0-255. In fact, any Unix program will only ever return a max of 255.

Additionally, many OS's/programs reserve > 127 for system designated codes, so you shouldn't even use anything above that.

If you need more return codes than 126 (since 0 is no error), consider writing it to STDOUT and hooking that.

Community
  • 1
  • 1
CosmicDan
  • 61
  • 2
  • 9