ptrace(), fork(), sleep(), exit(), SIGCHLD

Bruce Janson (bruce@cs.usyd.edu.au)
Mon, 13 Aug 2001 19:29:32 +1100


Hi,
The following program behaves incorrectly when traced:

$ uname -a
Linux dependo 2.4.2-2 #1 Sun Apr 8 19:37:14 EDT 2001 i686 unknown
$ cc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
$ strace -V
strace -- version 4.2
$ cat t.c
main()
{
switch (fork())
{
case -1:
write(2, "fork\n", 5);
break;

case 0:
usleep(1000000);
break;

default:
if (usleep(5000000) == -1)
write(2, "wrong\n", 6);
break;
}

exit(0);
}
$ cc t.c
$ time ./a.out

real 0m5.011s
user 0m0.000s
sys 0m0.000s
$ time strace -o /dev/null ./a.out
wrong

real 0m1.025s
user 0m0.010s
sys 0m0.010s
$

The problem appears to be that, when traced, the child process' exit()
interrupts the parent's usleep() with a SIGCHLD, the latter returning EINTR.
It also fails in the same way under Linux 2.2.16 and 2.2.19.

What am I missing?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/