Closing child processes when closing a tab/session

103 views
Skip to first unread message

gabriele renzi

unread,
Nov 9, 2016, 3:08:46 AM11/9/16
to iterm2-discuss
Hi everyone,

is it possible to configure iTerm so that closing a tab terminates all child processes?

Namely, given this flow:

1. I open a new tab
2. I start some process in the new tab (i.e. "tail -f somefile")
3. I open another tab, and I close the first one
4. doing "ps | grep somefile" in the new tab I still see the "tail"

what I would expect is that all non daemon-ized child processes would just quit,
but they hang around. 
I think what I'm saying is that I'd expect each shell in a tab to act as a session leader,
and closing it should kill all child processes, but this does not happen.

I tried to find info regarding this in the archives and on the internet at large, but my 
search-fu is not enough.

FWIW, I am using iTerm2 (Build 3.0.10) on macOS Sierra (10.12.1)

George Nachman

unread,
Nov 10, 2016, 12:09:24 AM11/10/16
to iterm2-...@googlegroups.com
Shells should be session leaders in 3.0.10. This part of unix is a mess, so it's also possible I forgot a magic system call :). In general when this issue appears it's because SIGHUP is blocked by the child process (that's how the shell kills its children). I wouldn't expect that to be the case for something like tail, though.

The other possibility is that you didn't wait long enough. We don't actually kill the process for five seconds after the tab is closed so you can undo closing it with cmd-z.

If your job dies with SIGHUP and it sticks around for longer than five seconds (or whatever value is configured in prefs>profiles>sessions for the Undo timeout), please open an issue and we'll track it down. https://iterm2.com/bugs

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gabriele renzi

unread,
Nov 10, 2016, 5:09:47 AM11/10/16
to iterm2-...@googlegroups.com
Interesting, I was trying to check again now and it seems the child "tail" process _does_ die.

But the funny thing is: I still have the test one I started yesterday! :)

So I seem to have found the problematic condition: 
if you background the tail process (<ctrl+z>bg) and quit the shell with (<ctrl+d>) the process survives. 
The process _does_ die if I do 

kill -HUP <pid>

BUT: it seems the same works across remote ssh sessions to a linux box, 

so I guess this is just me misunderstanding unix, and not a problem with iTerm.


Thanks for your help!



--
You received this message because you are subscribed to a topic in the Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/iterm2-discuss/muxOJHmsFZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to iterm2-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
twitter: @riffraff
blog (en, it): www.riffraff.info

George Nachman

unread,
Nov 11, 2016, 5:18:22 PM11/11/16
to iterm2-...@googlegroups.com

gabriele renzi

unread,
Nov 12, 2016, 3:49:16 AM11/12/16
to iterm2-...@googlegroups.com
yep, I found that out in the end but forgot to post here.
It appears the "huponexit" option changed default from on to off
at some point.
(In bash 2.x, but I might have been remembering very old systems)

In case anyone ends up on this thread, the equivalent for zsh appears to be 
the nohup flag for setopt.

Thanks for your help!
>>>> To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.

>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the Google Groups "iterm2-discuss" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/topic/iterm2-discuss/muxOJHmsFZc/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to iterm2-discus...@googlegroups.com.

>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>> twitter: @riffraff
>> blog (en, it): www.riffraff.info
>>
>> --
>> You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "iterm2-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/iterm2-discuss/muxOJHmsFZc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to iterm2-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages