strace/test/procpollable.c

45 lines
633 B
C
Raw Permalink Normal View History

1999-02-19 03:21:36 +03:00
#include <stdio.h>
#include <stdlib.h>
1999-02-19 03:21:36 +03:00
#include <signal.h>
#include <sys/procfs.h>
#include <sys/stropts.h>
#include <poll.h>
int main(int argc, char *argv[])
1999-02-19 03:21:36 +03:00
{
int pid;
char proc[32];
FILE *pfp;
struct pollfd pfd;
pid = fork();
if (pid == 0) {
1999-02-19 03:21:36 +03:00
pause();
exit(0);
}
1999-02-19 03:21:36 +03:00
sprintf(proc, "/proc/%d", pid);
pfp = fopen(proc, "r+");
if (pfp == NULL)
1999-02-19 03:21:36 +03:00
goto fail;
1999-02-19 03:21:36 +03:00
if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
goto fail;
1999-02-19 03:21:36 +03:00
pfd.fd = fileno(pfp);
pfd.events = POLLPRI;
1999-02-19 03:21:36 +03:00
if (poll(&pfd, 1, 0) < 0)
goto fail;
1999-02-19 03:21:36 +03:00
if (!(pfd.revents & POLLPRI))
goto fail;
1999-02-19 03:21:36 +03:00
kill(pid, SIGKILL);
exit(0);
fail:
kill(pid, SIGKILL);
exit(1);
}