|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1988 Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)kill.c 4.6 (Berkeley) 5/31/90"; ! 28: #endif /* not lint */ ! 29: ! 30: #include <signal.h> ! 31: #include <stdio.h> ! 32: #include <ctype.h> ! 33: ! 34: static char *signals[] = { ! 35: "hup", "int", "quit", "ill", "trap", "iot", /* 1 - 6 */ ! 36: "emt", "fpe", "kill", "bus", "segv", "sys", /* 7 - 12 */ ! 37: "pipe", "alrm", "term", "urg", "stop", "tstp", /* 13 - 18 */ ! 38: "cont", "chld", "ttin", "ttou", "io", "xcpu", /* 19 - 24 */ ! 39: "xfsz", "vtalrm", "prof", "winch", "29", "usr1", /* 25 - 30 */ ! 40: "usr2", NULL, /* 31 - 32 */ ! 41: }; ! 42: ! 43: main(argc, argv) ! 44: int argc; ! 45: char **argv; ! 46: { ! 47: register int numsig; ! 48: register char **p; ! 49: int errors; ! 50: ! 51: if (argc < 2) ! 52: usage(); ! 53: ! 54: if (!strcmp(*++argv, "-l")) { ! 55: printsig(); ! 56: exit(0); ! 57: } ! 58: ! 59: numsig = SIGTERM; ! 60: if (**argv == '-') { ! 61: ++*argv; ! 62: if (isalpha(**argv)) { ! 63: if (!strncasecmp(*argv, "sig", 3)) ! 64: *argv += 3; ! 65: for (p = signals;; ++p) { ! 66: if (!*p) ! 67: goto error; ! 68: if (!strcasecmp(*p, *argv)) { ! 69: numsig = p - signals + 1; ! 70: break; ! 71: } ! 72: } ! 73: } ! 74: else if (isdigit(**argv)) { ! 75: numsig = atoi(*argv); ! 76: if (numsig <= 0 || numsig > NSIG) ! 77: goto error; ! 78: } ! 79: else { ! 80: error: printf("kill: unknown signal %s; valid signals:\n", *argv); ! 81: printsig(); ! 82: exit(1); ! 83: } ! 84: ++argv; ! 85: } ! 86: ! 87: if (!*argv) ! 88: usage(); ! 89: ! 90: for (errors = 0; *argv; ++argv) { ! 91: if (!isdigit(**argv)) ! 92: usage(); ! 93: if (kill(atoi(*argv), numsig) == -1) { ! 94: perror(*argv); ! 95: errors = 1; ! 96: } ! 97: } ! 98: exit(errors); ! 99: } ! 100: ! 101: static ! 102: printsig() ! 103: { ! 104: register char **p; ! 105: ! 106: for (p = signals; *p; ++p) { ! 107: printf("%s ", *p); ! 108: if ((p - signals) == NSIG / 2 - 1) ! 109: printf("\n"); ! 110: } ! 111: printf("\n"); ! 112: } ! 113: ! 114: static ! 115: usage() ! 116: { ! 117: printf("usage: kill [-l] [-sig] pid ...\n"); ! 118: exit(2); ! 119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.