I'm ptrace'ing a process. After fork/exec and then a wait on the
child, I'm getting a status of 2943. I'm testing for failure, but
waitpid reports non-failure. I've looked in <sys/wait.h>, but the
value 2943 is not defined and does not appear to be a bit mask.
Any ideas on where I should look?
int DoParentProcess(int childPid)
{
int err, ret, status;
for( ; ; )
{
ret = waitpid(childPid, &status, 0);
err = errno;
///////////////////////////////////////
if(ret == -1)
{
cerr << "Failed to wait on child process, errno = " << err <<
endl;
return err;
}
///////////////////////////////////////
cout << "Parent: wait status = " << status << endl;
if(WIFEXITED(status))
break;
///////////////////////////////////////
ret = ptrace(PTRACE_CONT, childPid, 0, 0);
err = errno;
if(ret == -1)
{
cerr << "Failed to continue child process, errno = " << err <<
endl;
return err;
}
}
return 0;
}
Don't try to pick apart the bits by hand and especially don't try to treat
the glibc header files as human-readable. <sys/wait.h> provides macros that
you can use in C code to determine what an exit status means. So write the C
code. Trying to parse <sys/wait.h> with your pathetic human brain will lead
to frustration.
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
int main(void)
{
int status = 2943;
if(WIFEXITED(status)) {
printf("Exit status %d\n", WEXITSTATUS(status));
} else if(WIFSIGNALED(status)) {
printf("Terminated by signal %d (%s)%s\n",
WTERMSIG(status),
strsignal(WTERMSIG(status)),
WCOREDUMP(status)?" (core dumped)":"");
} else if(WIFSTOPPED(status)) {
printf("Stopped by signal %d (%s)\n",
WSTOPSIG(status),
strsignal(WSTOPSIG(status)));
} else if(WIFCONTINUED(status)) {
printf("Continued\n");
}
}
--
Alan Curry
Jeff
At the corresponding hexnumber which is 0xb7f, meaning (AFAIK), your process
was stopped by a SIGSEGV. A fairly human-readable version of the code
generating and analysing these numbers should be in
/usr/include/bits/waitstatus.h. The relevant macro is
#define __W_STOPCODE(sig) ((sig) << 8 | 0x7f)
You can just right shift the status by 8 and get the actual status.
No. Provided the lower order byte has a value of 0, you can do that.