procctl.c revision 31691
1/* 2 * procctl -- clear the event mask, and continue, any specified processes. 3 * This is largely an example of how to use the procfs interface; however, 4 * for now, it is also sometimes necessary, as a stopped process will not 5 * otherwise continue. (This will be fixed in a later version of the 6 * procfs code, almost certainly; however, this program will still be useful 7 * for some annoying circumstances.) 8 */ 9/* 10 * $Id: procctl.c,v 1.1 1997/12/06 04:19:09 sef Exp $ 11 */ 12 13#include <stdio.h> 14#include <stdlib.h> 15#include <string.h> 16#include <errno.h> 17#include <err.h> 18#include <signal.h> 19#include <fcntl.h> 20#include <sys/ioctl.h> 21#include <sys/pioctl.h> 22 23main(int ac, char **av) { 24 int fd; 25 int i; 26 unsigned int mask; 27 char **command; 28 struct procfs_status pfs; 29 30 for (i = 1; i < ac; i++) { 31 char buf[32]; 32 33 sprintf(buf, "/proc/%s/mem", av[i]); 34 fd = open(buf, O_RDWR); 35 if (fd == -1) { 36 if (errno == ENOENT) 37 continue; 38 fprintf(stderr, "%s: cannot open pid %s: %s\n", 39 av[0], av[i], strerror(errno)); 40 continue; 41 } 42 if (ioctl(fd, PIOCBIC, ~0) == -1) { 43 fprintf(stderr, "%s: cannot clear process %s's event mask: %s\n", 44 av[0], av[i], strerror(errno)); 45 } 46 if (ioctl(fd, PIOCCONT, 0) == -1 && errno != EINVAL) { 47 fprintf(stderr, "%s: cannot continue process %s: %s\n", 48 av[0], av[i], strerror(errno)); 49 } 50 close(fd); 51 } 52 return 0; 53} 54