Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 2 | #include <stdlib.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 3 | #include <signal.h> |
| 4 | #include <sys/procfs.h> |
| 5 | #include <sys/stropts.h> |
| 6 | #include <poll.h> |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 7 | |
| 8 | int main(int argc, char *argv[]) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 9 | { |
| 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 Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 19 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 20 | sprintf(proc, "/proc/%d", pid); |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 21 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 22 | if ((pfp = fopen(proc, "r+")) == NULL) |
| 23 | goto fail; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 24 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 25 | if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0) |
| 26 | goto fail; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 27 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 28 | pfd.fd = fileno(pfp); |
| 29 | pfd.events = POLLPRI; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 30 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 31 | if (poll(&pfd, 1, 0) < 0) |
| 32 | goto fail; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 33 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 34 | if (!(pfd.revents & POLLPRI)) |
| 35 | goto fail; |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 36 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 37 | kill(pid, SIGKILL); |
| 38 | exit(0); |
| 39 | fail: |
| 40 | kill(pid, SIGKILL); |
| 41 | exit(1); |
| 42 | } |