blob: a841af147c9eb3f118fe76b71567628bac7c64d4 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001#include <stdio.h>
Denys Vlasenko8ed57272009-02-25 14:24:02 +00002#include <stdlib.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00003#include <signal.h>
4#include <sys/procfs.h>
5#include <sys/stropts.h>
6#include <poll.h>
Denys Vlasenko8ed57272009-02-25 14:24:02 +00007
8int main(int argc, char *argv[])
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00009{
10 int pid;
11 char proc[32];
12 FILE *pfp;
13 struct pollfd pfd;
14
15 if ((pid = fork()) == 0) {
16 pause();
17 exit(0);
18 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000019
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000020 sprintf(proc, "/proc/%d", pid);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000021
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000022 if ((pfp = fopen(proc, "r+")) == NULL)
23 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000024
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000025 if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
26 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000027
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000028 pfd.fd = fileno(pfp);
29 pfd.events = POLLPRI;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000030
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000031 if (poll(&pfd, 1, 0) < 0)
32 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000033
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034 if (!(pfd.revents & POLLPRI))
35 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000036
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037 kill(pid, SIGKILL);
38 exit(0);
39fail:
40 kill(pid, SIGKILL);
41 exit(1);
42}