4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/types.h>
38 static int stop(char *);
39 static int lwpstop(int *, const lwpstatus_t
*, const lwpsinfo_t
*);
42 static const char *lwps
;
43 static struct ps_prochandle
*P
;
46 main(int argc
, char **argv
)
50 if ((command
= strrchr(argv
[0], '/')) != NULL
)
56 (void) fprintf(stderr
, "usage:\t%s pid[/lwps] ...\n", command
);
57 (void) fprintf(stderr
,
58 " (stop processes or lwps with /proc request)\n");
74 if ((P
= proc_arg_xgrab(arg
, NULL
, PR_ARG_PIDS
, PGRAB_RETAIN
|
75 PGRAB_NOSTOP
| PGRAB_FORCE
, &gcode
, &lwps
)) == NULL
) {
76 (void) fprintf(stderr
, "%s: cannot control %s: %s\n",
77 command
, arg
, Pgrab_error(gcode
));
79 } else if (lwps
!= NULL
) {
81 * The user has provided an lwp specification. Let's consider
82 * the lwp specification as a mask. We iterate over all lwps in
83 * the process and stop every lwp, which matches the mask. If
84 * there is no lwp matching the mask or an error occured during
85 * the iteration, set the return code to 1 as indication of an
90 (void) Plwp_iter_all(P
, (proc_lwp_all_f
*)lwpstop
, &lwpcount
);
92 (void) fprintf(stderr
, "%s: cannot control %s:"
93 " no matching LWPs found\n", command
, arg
);
95 } else if (lwpcount
== -1)
98 (void) Pdstop(P
); /* Stop the process. */
102 * Prelease could change the tracing flags, use Pfree and unset
103 * run-on-last-close flag to prevent the process being set running
104 * after detaching from it.
106 (void) Punsetflags(P
, PR_RLC
);
113 lwpstop(int *lwpcount
, const lwpstatus_t
*status
, const lwpsinfo_t
*info
)
115 struct ps_lwphandle
*L
;
118 if (proc_lwp_in_set(lwps
, info
->pr_lwpid
)) {
120 * There is a race between the callback from the iterator and
121 * grabbing of the lwp. If the lwp has already exited, Lgrab
122 * will return the error code G_NOPROC. It's not a real error,
123 * only if there is no lwp matching the specification.
125 if ((L
= Lgrab(P
, info
->pr_lwpid
, &gcode
)) != NULL
) {
130 } else if (gcode
!= G_NOPROC
) {
131 (void) fprintf(stderr
, "%s: cannot control %d/%d: %s\n",
132 command
, (int)Pstatus(P
)->pr_pid
,
133 (int)info
->pr_lwpid
, Lgrab_error(gcode
));