当我在shell中键入此命令时
ssh 127.0.0.1“sleep 10”&
我继续在键盘上单击“Enter”,此过程将停止,如下所示:
[4] +停止ssh 127.0.0.1“睡10”
如果我没有点击“输入”,它将完成
为什么?
答案 0 :(得分:1)
参见手册页:
-n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background. A common trick is
to use this to run X11 programs on a remote machine. For example, ssh -n shadows.cs.hut.fi emacs & will start an emacs on shadows.cs.hut.fi, and
the X11 connection will be automatically forwarded over an encrypted channel. The ssh program will be put in the background. (This does not
work if ssh needs to ask for a password or passphrase; see also the -f option.)
答案 1 :(得分:0)
在我的系统上,即使没有键盘输入,它也会停止:
$ ssh 127.0.0.1 "sleep 10" &
[1] 14986
$ jobs
[1]+ Stopped ssh 127.0.0.1 "sleep 10"
但是,以下内容继续运行:
$ ssh 127.0.0.1 "sleep 10" </dev/null &
[1] 15580
$ jobs
[1]+ Running ssh 127.0.0.1 "sleep 10" < /dev/null &
显然ssh
正在寻找输入,并且作为后台进程无法获得输入。从/ dev / null重定向stdin告诉它不要打扰,它甚至在后台继续运行。
更新:以上内容与文档中的@BraveNewCurrency相符:要使ssh
在后台运行,必须从/dev/null
重定向输入,{{1提供了一个有效的选项ssh
。