procctl.c revision 31565
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$ 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 mask = ~0; 43 if (ioctl(fd, PIOCBIC, &mask) == -1) { 44 fprintf(stderr, "%s: cannot clear process %s's event mask: %s\n", 45 av[0], av[i], strerror(errno)); 46 } 47 mask = 0; 48 if (ioctl(fd, PIOCCONT, &mask) == -1 && errno != EINVAL) { 49 fprintf(stderr, "%s: cannot continue process %s: %s\n", 50 av[0], av[i], strerror(errno)); 51 } 52 close(fd); 53 } 54 return 0; 55} 56