blob: 7bc5efafdf73c5d32784d8193a1b82522ea780a6 [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
Denys Vlasenko5d645812011-08-20 12:48:18 +020015 pid = fork();
16 if (pid == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000017 pause();
18 exit(0);
19 }
Denys Vlasenko8ed57272009-02-25 14:24:02 +000020
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000021 sprintf(proc, "/proc/%d", pid);
Denys Vlasenko8ed57272009-02-25 14:24:02 +000022
Denys Vlasenko5d645812011-08-20 12:48:18 +020023 pfp = fopen(proc, "r+");
24 if (pfp == NULL)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000025 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000026
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000027 if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
28 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000029
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000030 pfd.fd = fileno(pfp);
31 pfd.events = POLLPRI;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000032
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033 if (poll(&pfd, 1, 0) < 0)
34 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000035
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036 if (!(pfd.revents & POLLPRI))
37 goto fail;
Denys Vlasenko8ed57272009-02-25 14:24:02 +000038
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039 kill(pid, SIGKILL);
40 exit(0);
41fail:
42 kill(pid, SIGKILL);
43 exit(1);
44}