WEXITSTATUS
WEXITSTATUS is a macro used in POSIX-compliant systems to obtain the exit status of a child process from the status value returned by wait or waitpid. It is defined in the header sys/wait.h and is used in conjunction with other wait-related macros such as WIFEXITED and WIFSIGNALED.
After a call to wait or waitpid, you receive an int status. You should first check whether
The status value can also indicate other termination reasons, such as termination by a signal. In that
WEXITSTATUS, along with WIFEXITED and related macros, are part of the POSIX wait macros and are available
int code = WEXITSTATUS(status); // code == 2
}