Reputation: 12817
I'm trying to call a program and get its return value. I use fork()
and execv()
to call the child process, and now waiting for a status, but I receive 56
as the exit status, and I don't understand why. I've checked the child process separately, and it works just fine.
What does 56 mean and how can I fix it?
This is a part the relevant code:
pid_t pid = fork();
if (pid < 0)
// handle error
if (pid == 0)
execv(filename, argv); // calls child process
waitpid(pid, &status, 0);
if (WIFEXITED(status))
// handle success
else if(WIFSIGNALED(status))
printf("%d\n", (int) WTERMSIG(status)); // here I get 56 now, when I print the error using stderror I get this: "Invalid request code"
Upvotes: 1
Views: 3698
Reputation: 12619
You are not printing the exit status, but the number of signal that terminated the process. When the child process exits normally (WIFEXITED), you're not printing anything. It should be like this:
if (WIFEXITED(status))
printf("%d\n", (int)WEXITSTATUS(status));
Upvotes: 2