Skip to content

Instantly share code, notes, and snippets.

@edenhill
Created January 17, 2014 09:51
Show Gist options
  • Save edenhill/8470811 to your computer and use it in GitHub Desktop.
Save edenhill/8470811 to your computer and use it in GitHub Desktop.
WIFEXIT
/**
* Returns a human readable process exit reason based on the exit code.
*/
const char *exec_exitstatus (int status) {
static __thread char ret[128];
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 127)
snprintf(ret, sizeof(ret),
"could not execute command");
else
snprintf(ret, sizeof(ret), "exited with status %i",
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
#ifdef WCOREDUMP
if (WCOREDUMP(status))
snprintf(ret, sizeof(ret), "core dumped");
else
#endif
snprintf(ret, sizeof(ret), "terminated by signal %i",
WTERMSIG(status));
} else
snprintf(ret, sizeof(ret), "exited with code %i", status);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment