Welcome to mirror list, hosted at ThFree Co, Russian Federation.

kill.cc « utils « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6118878960b1f267fdcf92a60a8e29992f14ac3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* kill.cc

   Copyright 1996, 1997, 1998 Cygnus Solutions.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <time.h>

static void usage (void);
static int getsig (char *);
int a = _timezone;

int
main (int ac, char **av)
{
  int sig = SIGTERM;

  if (ac == 1)
    usage ();

  if (*(++av)[0] == '-')
    if (strcmp(*av + 1, "0") != 0)
      sig = getsig (*av++ + 1);
    else
      {
	av++;
	sig = 0;
	goto sig0;
      }

  if (sig <= 0 || sig > NSIG)
    {
      fprintf (stderr, "kill: unknown signal: %s\n", av[-1]);
      exit (1);
    }

sig0:
  while (*av != NULL)
    {
      char *p;
      int pid = strtol (*av, &p, 10);
      if (*p != '\0')
	fprintf (stderr, "kill: illegal pid: %s\n", *av);
      else
	{
	  printf ("Sending %s(%d) signal to pid %d\n",
		  strsignal (sig), sig, pid);
	  if (kill (pid, sig))
	    perror ("kill");
	}
      av++;
    }
  return 0;
}

static void
usage (void)
{
  fprintf (stderr, "Usage: kill [-sigN] pid1 [pid2 ...]\n");
  exit (1);
}

static int
getsig (char *in_sig)
{
  char *sig;
  char buf[80];

  if (strncmp (in_sig, "SIG", 3) == 0)
    sig = in_sig;
  else
    {
      sprintf (buf, "SIG%s", in_sig);
      sig = buf;
    }
  return (strtosigno (sig) ?: atoi (in_sig));
}