NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: killing `ssh <host> <cmd>' does not kill <cmd> on <host>



On Tue, Dec 9, 2008 at 9:53 AM, Petar Bogdanovic <petar%smokva.net@localhost> 
wrote:
> Hi,
>
> when I run a `never ending' command like:
>
>   ssh host tail -f /var/log/maillog.0
>
> CTRL-C-ing ssh after tail has reached the end of maillog.0 does not kill
> tail. If tail however suddenly would start to generate output again, it
> would die immediately.
>
> This is not that much of a problem if the process just sleeps and does
> nothing but there are certain cases where a running script soon will eat
> too much memory if not killed immediately.
>
> Here's how `ps aux' on <host> looks like after killing the ssh client:
>
>   petar    9401  0.0  0.7  228   876 ?       Is    3:14PM 0:00.00 ksh -c ksh
>   petar   15882  0.0  0.4   44   556 ?       I     3:14PM 0:00.00 tail -f 
> /var/log/maillog.0
>
>
> Is this desired behaviour? If not, how could one avoid it?
>

Use ssh -t when doing tail -f so that ssh creates a tty and ends a
command when it stops executing.

With -t:
$ ps auxwww|grep [t]ail
msporled 3556  0.0  0.4   32   492 ttyp3 S+   10:16AM 0:00.03 tail -f
/var/log/messages
msporled 4714  0.0  0.6  220   788 ttyp3 Ss+  10:16AM 0:00.03 ksh -c
tail -f /var/log/messages

(notice ttyp3)

Without -t:
$ ps auxwww|grep [t]ail
msporled 5243  0.0  0.6  220   788 ?     Ss   10:17AM 0:00.03 ksh -c
tail -f /var/log/messages
msporled 5265  0.0  0.4   32   492 ?     S    10:17AM 0:00.05 tail -f
/var/log/messages

(running in the background?)

Matt


Home | Main Index | Thread Index | Old Index