1: static  char *sccsid = "@(#)kill.c	4.4 (Berkeley) 4/20/86";
   2: /*
   3:  * kill - send signal to process
   4:  */
   5: 
   6: #include <signal.h>
   7: #include <ctype.h>
   8: 
   9: char *signm[] = { 0,
  10: "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "EMT", "FPE",   /* 1-8 */
  11: "KILL", "BUS", "SEGV", "SYS", "PIPE", "ALRM", "TERM", "URG",    /* 9-16 */
  12: "STOP", "TSTP", "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU",   /* 17-24 */
  13: "XFSZ", "VTALRM", "PROF", "WINCH", 0, "USR1", "USR2", 0,    /* 25-31 */
  14: };
  15: 
  16: main(argc, argv)
  17: char **argv;
  18: {
  19:     register signo, pid, res;
  20:     int errlev;
  21:     extern char *sys_errlist[];
  22:     extern errno;
  23: 
  24:     errlev = 0;
  25:     if (argc <= 1) {
  26:     usage:
  27:         printf("usage: kill [ -sig ] pid ...\n");
  28:         printf("for a list of signals: kill -l\n");
  29:         exit(2);
  30:     }
  31:     if (*argv[1] == '-') {
  32:         if (argv[1][1] == 'l') {
  33:             for (signo = 0; signo <= NSIG; signo++) {
  34:                 if (signm[signo])
  35:                     printf("%s ", signm[signo]);
  36:                 if (signo == 16)
  37:                     printf("\n");
  38:             }
  39:             printf("\n");
  40:             exit(0);
  41:         } else if (isdigit(argv[1][1])) {
  42:             signo = atoi(argv[1]+1);
  43:             if (signo < 0 || signo > NSIG) {
  44:                 printf("kill: %s: number out of range\n",
  45:                     argv[1]);
  46:                 exit(1);
  47:             }
  48:         } else {
  49:             char *name = argv[1]+1;
  50:             for (signo = 0; signo <= NSIG; signo++)
  51:                 if (signm[signo] && !strcmp(signm[signo], name))
  52:                     goto foundsig;
  53:             printf("kill: %s: unknown signal; kill -l lists signals\n", name);
  54:             exit(1);
  55: foundsig:
  56:             ;
  57:         }
  58:         argc--;
  59:         argv++;
  60:     } else
  61:         signo = SIGTERM;
  62:     argv++;
  63:     while (argc > 1) {
  64:         if (!(isdigit(**argv) || **argv == '-'))
  65:             goto usage;
  66:         res = kill(pid = atoi(*argv), signo);
  67:         if (res<0) {
  68:             printf("%u: %s\n", pid, sys_errlist[errno]);
  69:             errlev = 1;
  70:         }
  71:         argc--;
  72:         argv++;
  73:     }
  74:     return(errlev);
  75: }

Defined functions

main defined in line 16; never used

Defined variables

sccsid defined in line 1; never used
signm defined in line 9; used 4 times
Last modified: 1986-04-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1019
Valid CSS Valid XHTML 1.0 Strict