ssh process control (terminal magic?)



Hi, on Linux (Ubuntu 8.04), when I start ssh as a background shell job (I have passwordless login set up), by hitting enter a couple of times, after about 3 seconds since the original command is issued I see that the ssh process is suspended:

$ ssh hv sleep 30 &
[1] 22468
$ <hit enter quickly>
$
$

[1]+ Stopped ssh hv sleep 30
$

Now if I have something that's continuously producing stdout, then I see the output until after about 3 seconds in:

$ ssh hv 'while true; do echo a; sleep 1; done' &
[1] 22486
$ a
<hit enter>
$ a
a
a
a
a
a
<after waiting, hit enter>
[1]+ Stopped ssh hv 'while true; do echo a; sleep 1; done'
$ <no more output>

Attempts to bg it don't work:

$ bg
[1]+ ssh hv 'while true; do echo a; sleep 1; done' &
$

[1]+ Stopped ssh hv 'while true; do echo a; sleep 1; done'
$

And fg can bring it back, but only after hitting enter:

$ ssh hv 'while true; do echo a; sleep 1; done' &
[1] 22596
$ a
a
a


[1]+ Stopped ssh hv 'while true; do echo a; sleep 1; done'
$ fg
ssh hv 'while true; do echo a; sleep 1; done'
<nothing is printed...until I hit enter, at which all the buffered-up "a"s are immediately dumped>
a
a
a
a
a
a
a


Furthermore, I can't kill this process using sigint, sigterm, sigquit, etc.:

$ ps
PID TTY TIME CMD
22515 pts/3 00:00:00 ssh
22546 pts/3 00:00:00 ps
32443 pts/3 00:00:03 bash
$ kill 22515
$
$

But I can kill it with the shell's job control kill:

$ kill %1
$
[1]+ Exit 143 ssh hv 'while true; do echo a; sleep 1; done'
$

Alternatively, I could fg the job, at which point it will immediately exit (handle the queued-up signals). Could anyone help explain this behavior? I'm interested in writing scripts to run commands remotely via ssh, but I clearly don't get how to control ssh. If it matters, this is all in "OpenSSH_4.7p1 Debian-8ubuntu1, OpenSSL 0.9.8g 19 Oct 2007". Thanks in advance for any guidance!



Relevant Pages

  • remote administration of upgrades
    ... server that I administer runs FreeBSD 4.8, ... have ssh access to ... don't want to fubar sshd and then not be able to ... kill only the ...
    (freebsd-questions)
  • Re: Can anyone please reproduce this crash in X on Sid?
    ... In both, if I kill the process corresponding to X *from within X*, ... either the machine freezes completely ... Ssh too freezes? ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Whats the correct way to kill X via remote SSH?
    ... I connect to the box with ssh and kill (with -9 ... However, on the computer with the LCD monitor that ran startx, it did ... and nvidia on a few different cards. ... It's just rare that I have to kill X ...
    (comp.os.linux.x)
  • Re: My First Linux Crash
    ... If the O.P. does not have another machine capable of running ssh, ... not responding. ... SysRQ-k is supposed to kill the current virtual console. ...
    (comp.os.linux.misc)
  • Re: Whats the correct way to kill X via remote SSH?
    ... I had to kill X.org session because it froze or whatever ... I connect to the box with ssh and kill ... Yep, zero on my Debian. ... "I've been on some fairways that are as good as the greens we putted on ...
    (comp.os.linux.x)