This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: signal handling: kill() successful, but nothing delivered
- From: Ángel González <keisial at gmail dot com>
- To: michi1 at michaelblizek dot twilightparadox dot com
- Cc: libc-help at sourceware dot org
- Date: Sun, 17 Mar 2013 23:08:57 +0100
- Subject: Re: signal handling: kill() successful, but nothing delivered
- References: <20130313173830.GA2201@grml>
El 13/03/13 18:38, michi1@michaelblizek.twilightparadox.com escribió:
> Hi!
>
> (I have sent this mail to the kernelnewbies list before, but I have not
> received any responses)
>
> I am trying to test for signal handling race conditions (specifically, I
> suspect the kernel side of connect() does interesting things if the server
> response arrives while the program executes a signal handler) and want to
> flood a program with lots of signals. So I have run this:
>
> ---
> #!/bin/bash
>
> while [ 1 -eq 1 ]; do
> killall -s SIGURG wget 2> /dev/null
> done
> ---
> ...and then then executed:
> strace wget -O - "http://kernel.org"
>
> ...
> connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("198.145.20.140")}, 16) = ? ERESTARTSYS (To be restarted)
> --- SIGURG (Urgent I/O condition) @ 0 (0) ---
> connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("198.145.20.140")}, 16) = ? ERESTARTSYS (To be restarted)
> --- SIGURG (Urgent I/O condition) @ 0 (0) ---
> connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("198.145.20.140")}, 16) = 0
> ...
>
> It shows that signals arrive, but no interesting behaviour yet. I suspect this
> is because the rate signals are sent is too low. So I come up with this:
>
> ---
> #include <sys/types.h>
> #include <signal.h>
>
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
> int pid;
> int rc = 0;
>
> if (argc < 2)
> return 1;
>
> pid = atoi(argv[1]);
>
> if (pid <= 1 || pid >= 65536)
> return 1;
>
> printf("kill %d %d\n", pid, SIGURG);
> while (kill(pid, SIGURG) == 0) {
> printf("signal sent\n"); /* probably slow, remove later */
> }
> perror("killloop end");
> return 0;
> }
> ---
> #!/bin/bash
>
> while [ 1 -eq 1 ]; do
> ./a.out `ps a|grep wget|grep -v grep|sed "s/^[^0-9]*\([0-9]*\).*$/\1/"`
> done
> ---
>
> The output looks like this:
> kill 15574 23
> signal sent
> signal sent
> signal sent
> ...
> signal sent
> signal sent
> signal sent
> killloop end: No such process
>
>
> However, no signal arrives. But if I change SIGURG to SIGTERM, they arrive!
> Why does SIGURG arrive when sent with "killall -s SIGURG wget", but not when
> sent with my test prog?
>
> -Michi
Two ideas:
- The default action of SIGURG is to be ignored
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
- Are you sure that pipe correctly returns the wget pid (and only one
instance is running) ? Why not use `pidof wget` instead?