signals handling: kill() successful, but nothing delivered

michi1 at michaelblizek.twilightparadox.com michi1 at michaelblizek.twilightparadox.com
Fri Mar 8 00:52:46 EST 2013


Hi!

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
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com



More information about the Kernelnewbies mailing list