Home | History | Annotate | Download | only in test
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <signal.h>
      4 #include <sys/procfs.h>
      5 #include <sys/stropts.h>
      6 #include <poll.h>
      7 
      8 int main(int argc, char *argv[])
      9 {
     10 	int pid;
     11 	char proc[32];
     12 	FILE *pfp;
     13 	struct pollfd pfd;
     14 
     15 	pid = fork();
     16 	if (pid == 0) {
     17 		pause();
     18 		exit(0);
     19 	}
     20 
     21 	sprintf(proc, "/proc/%d", pid);
     22 
     23 	pfp = fopen(proc, "r+");
     24 	if (pfp == NULL)
     25 		goto fail;
     26 
     27 	if (ioctl(fileno(pfp), PIOCSTOP, NULL) < 0)
     28 		goto fail;
     29 
     30 	pfd.fd = fileno(pfp);
     31 	pfd.events = POLLPRI;
     32 
     33 	if (poll(&pfd, 1, 0) < 0)
     34 		goto fail;
     35 
     36 	if (!(pfd.revents & POLLPRI))
     37 		goto fail;
     38 
     39 	kill(pid, SIGKILL);
     40 	exit(0);
     41 fail:
     42 	kill(pid, SIGKILL);
     43 	exit(1);
     44 }
     45