diff options
author | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:38:33 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-02-17 19:38:33 +0000 |
commit | 1fd5e000ace55b323124c7e556a7a864b972a5c4 (patch) | |
tree | dc4fcf1e5e22a040716ef92c496b8d94959b2baa /winsup/utils/kill.cc | |
parent | 369d8a8fd5e887eca547bf34bccfdf755c9e5397 (diff) | |
download | cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.tar.gz cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.tar.bz2 cygnal-1fd5e000ace55b323124c7e556a7a864b972a5c4.zip |
import winsup-2000-02-17 snapshot
Diffstat (limited to 'winsup/utils/kill.cc')
-rw-r--r-- | winsup/utils/kill.cc | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc new file mode 100644 index 000000000..611887896 --- /dev/null +++ b/winsup/utils/kill.cc @@ -0,0 +1,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)); +} |