Skip to contentSkip to conversation

signals handling: kill() successful, but nothing delivered

DISCUSSION michi1 at michaelblizek.twilightparadox.com 2 participants 3 messages Mar 8, 2013 – Mar 18, 2013

lore
Share & tools
lore
#0 lore raw

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

Signature · 2 lines
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
#1 lore raw

Hi!

Quoted 1 line · On 06:52 Fri 08 Mar , michi1 at michaelblizek.twilightparadox.com wrote:
       ./a.out `ps a|grep wget|grep -v grep|sed "s/^[^0-9]*\([0-9]*\).*$/\1/"`

The command above returned the strace pid. Fixed version:
./a.out ps a|grep wget|grep -v grep|grep -v strace|sed "s/^[^0-9]*\([0-9]*\).*$/\1/"

-Michi

Signature · 2 lines
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
#2 lore raw
Quoted 4 lines · On Mon, 18 Mar 2013 06:50:25 +0100, michi1 at…

Hi!

Quoted 1 line · On 06:52 Fri 08 Mar , michi1 at michaelblizek.twilightparadox.com wrote:

./a.out `ps a|grep wget|grep -v grep

To save the double grep, you can do something like this:

ps a | grep '[w]get' | ...

Figuring out why that works is left as an exercise for the reader...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130318/0c9e2bd2/attachment.bin