bad_waitpid

bad_waitpid - bad calls to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * bad calls to waitpid() */ #include <sys/types.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <err.h> #include "config.h" #include "test.h" static void wait_badpid(int pid, const char *desc) { int rv, x; rv = waitpid(pid, &x, 0); report_test2(rv, errno, EINVAL, NOSUCHPID_ERROR, desc); } static void wait_badstatus(void *ptr, const char *desc) { int rv, pid, x; pid = fork(); if (pid<0) { warn("UH-OH: fork failed"); return; } if (pid==0) { exit(0); } rv = waitpid(pid, ptr, 0); report_test(rv, errno, EFAULT, desc); waitpid(pid, &x, 0); } static void wait_unaligned(void) { int rv, pid, x; int status[2]; /* will have integer alignment */ char *ptr; pid = fork(); if (pid<0) { warn("UH-OH: fork failed"); return; } if (pid==0) { exit(0); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
/* start with proper integer alignment */ ptr = (char *)(&status[0]); /* generate improper alignment on platforms with restrictions*/ ptr++; rv = waitpid(pid, (int *)ptr, 0); report_survival(rv, errno, "wait with unaligned status"); if (rv<0) { waitpid(pid, &x, 0); } } static
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

bad_waitpid - bad calls to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online