简体   繁体   中英

The return code of an application is an int16_t?

When talking about starting a new process, you can do it using int system(char* command) . If you pass an non NULL parameter, you can get:

  • -1 if the child process cannot be started;
  • a return code of the child process otherwise;

note: in Unix/Linux the return code is located on the higher eight bits of the result, while the lower eight bits contain the termination reason code >{1}<, so a retcode equal to 1 will be returned as 256; you can get the actual return code by shifting the value eight bits to the right; there is also a macro named WEXITSTATUS() that does it for you.

Searching for the implementation of WEXITSTATUS() it's a shift 8 bits to the right.

#define WEXITSTATUS(x) (_W_INT(x) >> 8)

This is the reason why I tend to think that return codes are 2 bytes (and also from >{1}<). The quote is from a C course found online.

Ps I would like to know the difference between the return code and termination reason code, aren't they the same?

There s different reasons for termination:

  • process terminates calling return (explicitly or not)
  • process terminates after signal delivery
  • process stopped after signal delivery. This one is not really termination but need to be caught in many situations.

For each of theses terminations a code is accessible, respectively:

  • value returned (only low eight bits of it)
  • signal number
  • signal number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM