From bf89557b965b65cdaf9e19c5c46ee200420c354e Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 14 Dec 1996 06:01:00 +0000 Subject: Merge Lite2 mods, and -Wall cleaning. --- bin/kill/kill.1 | 79 ++++++++++++++++++++++++++++---------------- bin/kill/kill.c | 100 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 122 insertions(+), 57 deletions(-) (limited to 'bin/kill') diff --git a/bin/kill/kill.1 b/bin/kill/kill.1 index fabafc0..5359199 100644 --- a/bin/kill/kill.1 +++ b/bin/kill/kill.1 @@ -32,10 +32,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)kill.1 8.1 (Berkeley) 5/31/93 -.\" $Id: kill.1,v 1.2 1994/09/24 02:55:43 davidg Exp $ +.\" @(#)kill.1 8.2 (Berkeley) 4/28/95 +.\" $Id: kill.1,v 1.3 1996/07/03 22:19:50 wosch Exp $ .\" -.Dd May 31, 1993 +.Dd April 28, 1995 .Dt KILL 1 .Os .Sh NAME @@ -43,57 +43,74 @@ .Nd terminate or signal a process .Sh SYNOPSIS .Nm kill -.Op Fl signal_name +.Op Fl s Ar signal_name .Ar pid \&... .Nm kill -.Op Fl signal_number +.Fl l +.Op Ar exit_status +.Nm kill +.Fl signal_name .Ar pid \&... .Nm kill -.Op Fl l +.Fl signal_number +.Ar pid +\&... .Sh DESCRIPTION -The kill utility sends the -.Dv TERM -signal to the processes specified -by the pid operand(s). +The +.Nm +utility sends a signal to the processes specified by the pid operand(s). .Pp Only the super-user may send signals to other users' processes. .Pp The options are as follows: .Pp .Bl -tag -width Ds -.It Fl l -List the signal names. +.It Fl s Ar signal_name +A symbolic signal name specifying the signal to be sent instead of the +default +.Dv TERM . +.It Fl l Op Ar exit_status +If no operand is given, list the signal names; otherwise, write +the signal name corresponding to +.Ar exit_status . .It Fl signal_name A symbolic signal name specifying the signal to be sent instead of the default .Dv TERM . -The -.Fl l -option displays the signal names. .It Fl signal_number A non-negative decimal integer, specifying the signal to be sent instead of the default .Dv TERM . .El .Pp +The following pids have special meanings: +.Bl -tag -width Ds -compact +.It -1 +If superuser, broadcast the signal to all processes; otherwise broadcast +to all processes belonging to the user. +.El +.Pp Some of the more commonly used signals: -.Bd -ragged -offset indent -compact -.Bl -column XXX TERM -.It -1 -1 (super-user broadcast to all processes, or user broadcast -to user's processes) -.It 0 0 (sh(1) only, signals all members of process group) -.It 2 INT (interrupt) -.It 3 QUIT (quit) -.It 6 ABRT (abort) -.It 9 KILL (non-catchable, non-ignorable kill) -.It 14 ALRM (alarm clock) -.It 15 TERM (software termination signal) +.Bl -tag -width Ds -compact +.It 1 +HUP (hang up) +.It 2 +INT (interrupt) +.It 3 +QUIT (quit) +.It 6 +ABRT (abort) +.It 9 +KILL (non-catchable, non-ignorable kill) +.It 14 +ALRM (alarm clock) +.It 15 +TERM (software termination signal) .El -.Ed .Pp -.Nm Kill +.Nm is a built-in to .Xr csh 1 ; it allows job specifiers of the form ``%...'' as arguments @@ -109,6 +126,12 @@ for details. .Xr ps 1 , .Xr kill 2 , .Xr sigvec 2 +.Sh STANDARDS +The +.Nm +function is expected to be +.St -p1003.2 +compatible. .Sh HISTORY A .Nm kill diff --git a/bin/kill/kill.c b/bin/kill/kill.c index 7de25e1..0472d92 100644 --- a/bin/kill/kill.c +++ b/bin/kill/kill.c @@ -30,17 +30,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kill.c,v 1.2 1994/09/24 02:55:44 davidg Exp $ + * $Id: kill.c,v 1.3 1995/03/05 21:52:41 jkh Exp $ */ #ifndef lint -static char copyright[] = +static char const copyright[] = "@(#) Copyright (c) 1988, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)kill.c 8.3 (Berkeley) 4/2/94"; +static char const sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95"; #endif /* not lint */ #include @@ -52,7 +52,8 @@ static char sccsid[] = "@(#)kill.c 8.3 (Berkeley) 4/2/94"; #include void nosig __P((char *)); -void printsig __P((FILE *)); +void printsignals __P((FILE *)); +int signame_to_signum __P((char *)); void usage __P((void)); int @@ -60,30 +61,52 @@ main(argc, argv) int argc; char *argv[]; { - const char *const *p; int errors, numsig, pid; char *ep; if (argc < 2) usage(); - if (!strcmp(*++argv, "-l")) { - printsig(stdout); + numsig = SIGTERM; + + argc--, argv++; + if (!strcmp(*argv, "-l")) { + argc--, argv++; + if (argc > 1) + usage(); + if (argc == 1) { + if (!isdigit(**argv)) + usage(); + numsig = strtol(*argv, &ep, 10); + if (!*argv || *ep) + errx(1, "illegal signal number: %s", *argv); + if (numsig >= 128) + numsig -= 128; + if (numsig <= 0 || numsig >= NSIG) + nosig(*argv); + printf("%s\n", sys_signame[numsig]); + exit(0); + } + printsignals(stdout); exit(0); } - numsig = SIGTERM; - if (**argv == '-') { + if (!strcmp(*argv, "-s")) { + argc--, argv++; + if (argc < 1) { + warnx("option requires an argument -- s"); + usage(); + } + if (strcmp(*argv, "0")) { + if ((numsig = signame_to_signum(*argv)) < 0) + nosig(*argv); + } else + numsig = 0; + argc--, argv++; + } else if (**argv == '-') { ++*argv; if (isalpha(**argv)) { - if (!strncasecmp(*argv, "sig", 3)) - *argv += 3; - for (numsig = NSIG, p = sys_signame + 1; --numsig; ++p) - if (!strcasecmp(*p, *argv)) { - numsig = p - sys_signame; - break; - } - if (!numsig) + if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else if (isdigit(**argv)) { numsig = strtol(*argv, &ep, 10); @@ -93,13 +116,13 @@ main(argc, argv) nosig(*argv); } else nosig(*argv); - ++argv; + argc--, argv++; } - if (!*argv) + if (argc == 0) usage(); - for (errors = 0; *argv; ++argv) { + for (errors = 0; argc; argc--, argv++) { pid = strtol(*argv, &ep, 10); if (!*argv || *ep) { warnx("illegal process id: %s", *argv); @@ -109,38 +132,57 @@ main(argc, argv) errors = 1; } } + exit(errors); } +int +signame_to_signum(sig) + char *sig; +{ + int n; + + if (!strncasecmp(sig, "sig", 3)) + sig += 3; + for (n = 1; n < NSIG; n++) { + if (!strcasecmp(sys_signame[n], sig)) + return (n); + } + return (-1); +} + void nosig(name) char *name; { warnx("unknown signal %s; valid signals:", name); - printsig(stderr); + printsignals(stderr); exit(1); } void -printsig(fp) +printsignals(fp) FILE *fp; { - const char *const *p; - int cnt; + int n; - for (cnt = NSIG, p = sys_signame + 1; --cnt; ++p) { - (void)fprintf(fp, "%s ", *p); - if (cnt == NSIG / 2) + for (n = 1; n < NSIG; n++) { + (void)fprintf(fp, "%s", sys_signame[n]); + if (n == (NSIG / 2) || n == (NSIG - 1)) (void)fprintf(fp, "\n"); + else + (void)fprintf(fp, " "); } - (void)fprintf(fp, "\n"); } void usage() { - (void)fprintf(stderr, "usage: kill [-l] [-sig] pid ...\n"); + (void)fprintf(stderr, "usage: kill [-s signal_name] pid ...\n"); + (void)fprintf(stderr, " kill -l [exit_status]\n"); + (void)fprintf(stderr, " kill -signal_name pid ...\n"); + (void)fprintf(stderr, " kill -signal_number pid ...\n"); exit(1); } -- cgit v1.1