Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Status = 2943 from waitpid?

400 views
Skip to first unread message

Jeffrey Walton

unread,
Jun 9, 2011, 12:57:10 AM6/9/11
to
Hi All,

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;
}

Alan Curry

unread,
Jun 9, 2011, 2:03:18 AM6/9/11
to
In article <033817d4-c109-4d37...@a10g2000vbz.googlegroups.com>,

Jeffrey Walton <nolo...@gmail.com> wrote:
>Hi All,
>
>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.

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

Jeffrey Walton

unread,
Jun 9, 2011, 8:27:15 AM6/9/11
to
On Jun 9, 2:03 am, pac...@kosh.dhis.org (Alan Curry) wrote:
> In article <033817d4-c109-4d37-a476-f7710b7ed...@a10g2000vbz.googlegroups.com>,
Thanks Alan - that did the trick. I was continuing a segfault. I've
got to locate my copy of APUE.

Jeff

Rainer Weikusat

unread,
Jun 9, 2011, 8:51:15 AM6/9/11
to
Jeffrey Walton <nolo...@gmail.com> writes:
> 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?

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)

Shankar

unread,
Jun 10, 2011, 2:25:46 AM6/10/11
to
On Jun 9, 8:51 am, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:

> Jeffrey Walton <noloa...@gmail.com> writes:
> > 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?
>

You can just right shift the status by 8 and get the actual status.

Rainer Weikusat

unread,
Jun 10, 2011, 10:04:13 AM6/10/11
to

No. Provided the lower order byte has a value of 0, you can do that.

0 new messages