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; 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:
return
(explicitly or not)For each of theses terminations a code is accessible, respectively:
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.