On 16 May 2017 at 12:56, <yuri.shakhma...@gmail.com> wrote: > > [... kill does not kill all the processes ...] Is this normal behavior? It > seems strange. >
One moment of enlightenment for me was to discover why CTRL-C at the terminal kills all of the processes, while kill(pid, SIG{whatever}) to the parent process does not. It's that CTRL-C doesn't just signal the parent process! It signals all processes in the process group of the session leader process whose controlling terminal is the current terminal. Phew, what a mouthful - I'm not even sure I stated that correctly. But anyway, CTRL-C doesn't do kill. It does kill_pgrp. Anyway, here's where it happens in linux: https://github.com/torvalds/linux/blob/a95cfad947d5f40cfbf9a d3019575aac1d8ac7a6/drivers/tty/n_tty.c#L1258 and ultimately... https://github.com/torvalds/linux/blob/a95cfad 947d5f40cfbf9ad3019575aac1d8ac7a6/drivers/tty/n_tty.c#L1085 Some more docs: http://www.informit.com/articles/article.aspx?p=397655&seqNum=6 I think this can be surprising, and it's not so obvious at first glance. Anyway, one implication of this is that if your process escapes the process group, then CTRL-C won't kill it. Also, Unix processes may quit for other reasons than receiving a signal, for example if a file descriptor they're reading from is closed (which might also happen when another process dies). Food for thought. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.