bug-bash
[Top][All Lists]
Advanced

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

Re: A background ssh can take over the tty from bash?


From: L A Walsh
Subject: Re: A background ssh can take over the tty from bash?
Date: Mon, 12 Jun 2017 20:00:41 -0700
User-agent: Thunderbird



Clark Wang wrote:
On Tue, Jun 13, 2017 at 2:48 AM, L A Walsh <address@hidden> wrote:

Clark Wang wrote:

I've checked the ssh process and it does not catch SIGTTIN and that's why
I'm confused.


----
   From what I understand, a background process will automatically
block when it tries to read from STDIN.  By definition, processes
become bg-processes by using '&'.  I haven't looked at the
code, but I'm guessing that the first 'ssh' that you launched
(*without* the '&') is the process swallowing your input as
it was declared to be a some sort of master-multiplexer for
subsequent slave processes, but that's just a guess.  Maybe
putting the master in background @ launch (using '&') will
cause it to auto-block(suspend) as you expect?


The first ssh (with `-f`) would fork another ssh running as a daemon which
would detach from the current tty.
---
   Which means from the shell's standpoint, it was no longer a normal
background process that would be prevented from reading input by being
sent a SIGTTIN.

being suspended
It makes no difference whether to use
`&` or not.
----
   By disconnecting from the controlling terminal (which
it would do regardless of whether '&' was used because it demonized),
you removed it from normal job-control where it might get a SIGTTIN.
Since you didn't disconnect it's input from your foreground terminal
it conflicted.  I.e. if you want SIGTTIN to function, you need to
have the background process remain in the TTY group -- not become a daemon.

  The most common way to put a process
in background and keep it in the same TTY group is using '&'.  If you
tell a process to background itself (not using '&'), many (though not
all) will disconnect from the controlling terminal and not stay
in your process group.

   In this case you need to use "-n" with "-f" OR not use
either if you wish it to be suspended.
   If I launch ssh without "-f" but put it in background, it doesn't
grab the foreground terminal (and the DOES get suspended when it
tries to do input).

Please see my explanation @stackoverflow:
https://stackoverflow.com/questions/44492312/ .
Seems to be saying similar -- that the demonizing process needs
to be disconnected from stdin.
It doesn't mention that you can have it be suspended
(as you seemed to expect), by not having it daemonize.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]