Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Possible bug in signal handling



On Nov 2,  2:10am, Dima Kogan wrote:
}
} I have a /tmp/tst.sh script:
} 
}    awk '{print; fflush()}' | \
}        perl -e 'BEGIN { $SIG{INT} = sub { $SIG{INT} = undef; }; } while(<>) {sleep 1;} sleep 10000;'
} 
} I invoke this script thusly:
} 
} $ seq 5000 | perl -nE 'say "xxx"; sleep(1)' | zsh /tmp/tst.sh
} 
} So it's a mostly do-nothing pipeline. When the user hits Ctrl-C the
} first time, I expect everything but the inner zsh and the inner perl
} processes to die, and the outer zsh to NOT display another prompt until
} a second Ctrl-C. Instead I see everything except the inner perl die
} (inner zsh dies too), and the prompt is returned immediately.

I'm able to get bash to orphan that perl process sometimes, too, just
not reliably.

The difference seems to be that bash calls waitpid() whereas zsh uses
sigpause() and doesn't do the wait*() until the SIGCHLD arrives.  The
order of arrival of the CHLD and INT signals may therefore determine
whether the shell continues waiting or not.

Changing the script to this --

   trap '' INT
   { trap - INT; awk '{print; fflush()}'; } | \
          perl -e 'BEGIN { $g = getpgrp($$); print "$g\n"; $SIG{INT} = sub {
$SIG{INT} = undef; }; } while(<>)
          {sleep 1;} sleep 10000;'

-- gets both shells to wait for perl to exit before the script exits.



Messages sorted by: Reverse Date, Date, Thread, Author