kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* signals handling: kill() successful, but nothing delivered
@ 2013-03-08  5:52 michi1 at michaelblizek.twilightparadox.com
  2013-03-18  5:50 ` michi1 at michaelblizek.twilightparadox.com
  0 siblings, 1 reply; 3+ messages in thread
From: michi1 at michaelblizek.twilightparadox.com @ 2013-03-08  5:52 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* signals handling: kill() successful, but nothing delivered
  2013-03-08  5:52 signals handling: kill() successful, but nothing delivered michi1 at michaelblizek.twilightparadox.com
@ 2013-03-18  5:50 ` michi1 at michaelblizek.twilightparadox.com
  2013-03-18 15:59   ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 3+ messages in thread
From: michi1 at michaelblizek.twilightparadox.com @ 2013-03-18  5:50 UTC (permalink / raw)
  To: kernelnewbies

Hi!

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* signals handling: kill() successful, but nothing delivered
  2013-03-18  5:50 ` michi1 at michaelblizek.twilightparadox.com
@ 2013-03-18 15:59   ` Valdis.Kletnieks at vt.edu
  0 siblings, 0 replies; 3+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-03-18 15:59 UTC (permalink / raw)
  To: kernelnewbies

On Mon, 18 Mar 2013 06:50:25 +0100, michi1 at michaelblizek.twilightparadox.com said:
> Hi!
>
> 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 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-18 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-08  5:52 signals handling: kill() successful, but nothing delivered michi1 at michaelblizek.twilightparadox.com
2013-03-18  5:50 ` michi1 at michaelblizek.twilightparadox.com
2013-03-18 15:59   ` Valdis.Kletnieks at vt.edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).