2 * Copyright 1997 Sean Eric Fagan
3 * Copyright (c) 2004 Liam J. Foy <liamfoy@sepulcrum.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Sean Eric Fagan
16 * 4. Neither the name of the author may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $FreeBSD: src/usr.sbin/procctl/procctl.c,v 1.6 2000/02/21 10:22:39 ru Exp $
33 * $DragonFly: src/usr.sbin/procctl/procctl.c,v 1.3 2004/12/06 21:13:51 liamfoy Exp $
37 * procctl -- clear the event mask, and continue, any specified processes.
38 * This is largely an example of how to use the procfs interface; however,
39 * for now, it is also sometimes necessary, as a stopped process will not
40 * otherwise continue. (This will be fixed in a later version of the
41 * procfs code, almost certainly; however, this program will still be useful
42 * for some annoying circumstances.)
52 #include <sys/ioctl.h>
53 #include <sys/param.h>
54 #include <sys/pioctl.h>
56 static void usage(void);
59 main(int argc
, char **argv
)
64 while ((c
= getopt(argc
, argv
, "v")) != -1) {
80 for (; *argv
; ++argv
) {
83 snprintf(buf
, sizeof(buf
), "/proc/%s/mem", *argv
);
84 fd
= open(buf
, O_RDWR
);
86 if (!vflag
&& errno
== ENOENT
)
88 warn("cannot open pid %s", *argv
);
92 if (ioctl(fd
, PIOCBIC
, ~0) == -1)
93 warn("cannot clear process %s's event mask", *argv
);
95 printf("successfully cleared process %s\n", *argv
);
97 if (ioctl(fd
, PIOCCONT
, 0) == -1 && errno
!= EINVAL
)
98 warn("cannot continue process %s", *argv
);
100 printf("process %s continued\n", *argv
);
110 fprintf(stderr
, "usage: procctl [-v] pid...\n");