[please CC, I don't follow -questions] Hello!
I've been struggling with an odd quirk in sh(1). Here is my sample code: --- 8< cut here 8< --- cleanup () { echo "cleaning up $pid" kill $pid } ( echo "in subshell" tail -f /etc/motd & pid=$! trap cleanup 1 2 15 wait $pid || echo "command failed" ) & wait --- 8< cut here 8< --- The idea is to be able *in the subshell* to cleanup a backgrounded command. The result is unexpected: [EMAIL PROTECTED]/src/local/bin/worldtools]% sh test_trap.sh in subshell FreeBSD 4.8-STABLE (SHALL) #0: Wed Aug 13 16:46:04 EDT 2003 Welcome to Shall, multi-purpose file/mail/web/ftp server. ^C [EMAIL PROTECTED]/src/local/bin/worldtools]% ps PID TT STAT TIME COMMAND 14162 p1 Ss 0:03,95 -zsh (zsh) 16918 p1 S 0:00,00 sh test_trap.sh 16919 p1 S 0:00,00 sh test_trap.sh 16920 p1 S 0:00,01 tail -f /etc/motd 16922 p1 R+ 0:00,00 ps i.e. the subshell doesn't call the trap!! I've searched long and large manuals, I even tried debugging (i'm about to build sh with debugging symbols now): the subshell *really* receives the signal, it just ignores it. The sh manpage says that: When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has no effect on signals that were ignored on entry to the shell. Well, it looks like calling trap in the subshell doesn't work. For reference, in bash and zsh behave correctly: [EMAIL PROTECTED]/src/local/bin/worldtools]% zsh test_trap.sh in subshell FreeBSD 4.8-STABLE (SHALL) #0: Wed Aug 13 16:46:04 EDT 2003 Welcome to Shall, multi-purpose file/mail/web/ftp server. ^Ccleaning up 16947 [EMAIL PROTECTED]/src/local/bin/worldtools]% command failed Is it me? Or do I head for GNATS? :) A. -- There has been only one Christian. They caught him and crucified him -- early. - Mark Twain
pgp00000.pgp
Description: PGP signature