2 Copyright 2007, Red Hat Inc. */
9 #include <asm/unistd.h>
11 #define tkill(tid, sig) syscall (__NR_tkill, (tid), (sig))
13 #define LENGTH(x) (sizeof (x) / sizeof (*(x)))
20 static const struct signal sigtab[] =
71 { SIGSTKFLT, "STKFLT" },
101 { SIGVTALRM, "VTALRM" },
107 { SIGWINCH, "WINCH" },
118 #ifdef disableSIGRTMIN /* initializer element is not constant */
119 { SIGRTMIN, "RTMIN" },
121 #ifdef disableSIGRTMAX /* initializer element is not constant */
122 { SIGRTMAX, "RTMAX" },
126 static void list (void)
128 const struct signal *sig;
130 for (sig = sigtab; sig < sigtab + LENGTH (sigtab); sig++)
131 printf ("%2d\t%s\n", sig->signo, sig->name);
137 __attribute__((__unused__))
139 void fail (const char *where)
141 fprintf (stderr, "Error parsing arguments: %s\n", where);
145 static int parse_number (const char *text)
150 val = strtol (text, &end, 0);
151 if (val >= 0 && (int) val == val && (end == NULL || *end == 0))
157 static int parse_signal (const char *text_orig)
159 const char *text = text_orig;
160 const struct signal *sig;
163 retval = parse_number (text);
167 if (strncasecmp (text, "SIG", 3) == 0)
169 for (sig = sigtab; sig < sigtab + LENGTH (sigtab); sig++)
170 if (strcasecmp (sig->name, text) == 0)
178 static void help (void)
183 tgkill {-s sigspec | -n sigspec | -sigspec} pid ...\n\
188 int main (int argc, char **argv)
193 if (argc == 2 && strcmp (argv[1], "-h") == 0)
195 if (argc == 2 && strcmp (argv[1], "-l") == 0)
198 if (argc > 3 && (strcmp (argv[1], "-s") == 0 || strcmp (argv[1], "-n") == 0))
200 signo = parse_signal (argv[2]);
203 else if (argc > 2 && argv[1][0] == '-')
205 signo = parse_signal (argv [1] + 1);
211 while (argp < argv + argc)
213 const char *arg = *argp++;
216 pid = parse_number (arg);
220 if (tkill (pid, signo) != 0)