- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
(我在 Debian 8 上使用 Bash 4.4.12。问题也在 bash mailing list 中提出。)
请参阅以下步骤重现该问题。
来自 tty #1 (pts/2
):
[STEP 101] # tty
/dev/pts/2
[STEP 102] # ssh -o ControlMaster=yes -o ControlPath=/tmp/socket.ssh -N -f 127.0.0.1
[STEP 103] # ps -C ssh u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1390 0.0 0.0 36440 656 ? Ss 11:33 0:00 ssh -o ControlMaster=yes -o ControlPath=/tmp/so
[STEP 104] #
[STEP 105] # ssh -o ControlMaster=no -o ControlPath=/tmp/socket.ssh \
127.0.0.1 sleep 3600 &
[1] 1396
[STEP 106] # <-- Here I cannot input anything except <CTRL-C>
STEP 102 启动了作为守护进程运行的多路复用 SSH 连接。 STEP 105 尝试使用多路复用连接来运行 sleep
命令。但是后来我无法在当前 shell 中输入任何内容。如果我终止 ssh ... sleep &
进程,那么 Bash 将能够再次接受我的输入。似乎所有输入都被后台 ssh
进程消耗了。
转到 tty #2 (pts/3
):
[STEP 201] # tty
/dev/pts/3
[STEP 202] # ps t pts/2 j
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
723 1353 1353 1353 pts/2 1353 Ss+ 0 0:00 bash
1353 1396 1396 1353 pts/2 1353 S 0 0:00 ssh -o ControlMaster=no -o ControlPath=/tmp/socket.ssh 127.0.0.1 sleep 3600
[STEP 203] # ps s 1396
UID PID PENDING BLOCKED IGNORED CAUGHT STAT TTY TIME COMMAND
0 1396 00000000 00000000 00001000 188004003 S pts/2 0:00 ssh -o ControlMaster=no -o ControlPath=/tmp/socket.ssh 127.0.0.1 sleep 3600
[STEP 204] #
我解码了信号掩码:
PENDING (00000000):
BLOCKED (00000000):
IGNORED (00001000):
13 PIPE
CAUGHT (188004003):
1 HUP
2 INT
15 TERM
28 WINCH
32
33
在这里我们可以看到 ssh 进程没有捕捉到 SIGTTIN
信号。这就是让我感到困惑的原因,因为后台作业(进程组)应该收到 SIGTTIN
并在它尝试从 tty 读取时停止。
最佳答案
我想我已经弄清楚发生了什么。让我解释一下。
来自 tty #1 (pts/2
):
[STEP 300] # tty
/dev/pts/2
[STEP 301] # ssh -o ControlMaster=yes -o ControlPath=/tmp/socket.ssh -N -f 127.0.0.1 < /dev/null >& /dev/null
[STEP 302] # ps -C ssh j
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 4052 4052 4052 ? -1 Ss 0 0:00 ssh -o ControlMaster=yes -o ControlPath=/tmp/socket.ssh -N -f 127.0.0.1
[STEP 303] # ls -l /proc/4052/fd/
total 0
lr-x------ 1 root root 64 2017-06-12 22:59 0 -> /dev/null
l-wx------ 1 root root 64 2017-06-12 22:59 1 -> /dev/null
l-wx------ 1 root root 64 2017-06-12 22:59 2 -> /dev/null
lrwx------ 1 root root 64 2017-06-12 22:59 3 -> socket:[370151]
lrwx------ 1 root root 64 2017-06-12 22:59 4 -> socket:[370201]
[STEP 304] # ssh -o ControlMaster=no -o ControlPath=/tmp/socket.ssh 127.0.0.1 sleep 3600 &
[1] 4062
[STEP 305] # <-- Cannot input anything
开始 tty #2 (pts/3
):
[STEP 401] # tty
/dev/pts/3
[STEP 402] # ps t pts/2 j
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
579 3552 3552 3552 pts/2 3552 Ss+ 0 0:00 bash
3552 4062 4062 3552 pts/2 3552 S 0 0:00 ssh -o ControlMaster=no -o ControlPath=/tmp/socket.ssh 127.0.0.1 sleep 3600
[STEP 403] # ls -l /proc/4062/fd/ # The `ssh ... sleep' process
total 0
lrwx------ 1 root root 64 2017-06-12 23:00 0 -> /dev/pts/2
lrwx------ 1 root root 64 2017-06-12 23:00 1 -> /dev/pts/2
lrwx------ 1 root root 64 2017-06-12 23:00 2 -> /dev/pts/2
lrwx------ 1 root root 64 2017-06-12 23:00 3 -> socket:[370349]
[STEP 404] # ls -l /proc/4052/fd/ # The `ssh -o ControlMaster=yes' process
total 0
lr-x------ 1 root root 64 2017-06-12 22:59 0 -> /dev/null
l-wx------ 1 root root 64 2017-06-12 22:59 1 -> /dev/null
l-wx------ 1 root root 64 2017-06-12 22:59 2 -> /dev/null
lrwx------ 1 root root 64 2017-06-12 22:59 3 -> socket:[370151]
lrwx------ 1 root root 64 2017-06-12 22:59 4 -> socket:[370201]
lrwx------ 1 root root 64 2017-06-12 23:02 5 -> socket:[370350]
lrwx------ 1 root root 64 2017-06-12 23:02 6 -> /dev/pts/2
lrwx------ 1 root root 64 2017-06-12 23:02 7 -> /dev/pts/2
lrwx------ 1 root root 64 2017-06-12 23:02 8 -> /dev/pts/2
[STEP 405] #
STEP 403 的输出显示 ssh ... sleep
进程' stdin/stdout/stderr 在 上打开点/2
。这是正常的。
但是 STEP 404 的输出(与 STEP 303 相比)显示 ssh -o ControlMaster=yes
进程也在打开 pts/2
。我相信这就是多路复用 SSH 的工作方式——新的 ssh ... sleep
进程通过 UNIX 域将其打开的文件描述符传递给 ssh -o ControlMaster=yes
进程套接字(-o ControlPath=/tmp/socket.ssh
)。所以实际上是 ssh -o ControlMaster=yes
进程消耗了来自 pts/2
的所有输入。并且由于 ssh -o ControlMaster=yes
进程与 bash
进程(和 ssh ... sleep
)不在同一个进程 session 中因此作业控制机制不适用于它,即使它在后台运行(作为守护进程)并从 pts/2
读取。
换句话说:SIGTTIN
仅发送到作为后台作业运行并尝试从其控制终端 读取的进程。这里 ssh -o ControlMaster=yes
进程在后台运行,但它不是 bash
process session 的工作,并且它没有控制终端。
关于通过 UNIX 域套接字在进程之间传递 FD 的更多信息(来自 Wikipedia ):
In addition to sending data, processes may send file descriptors across a Unix domain socket connection using the
sendmsg()
andrecvmsg()
system calls. This allows the sending processes to grant the receiving process access to a file descriptor for which the receiving process otherwise does not have access.
关于bash - 为什么后台 ssh 可以从 Bash 接管 tty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44492312/
我用 IntelliJ IDEA 2021.1 CE 在 流行!_OS 20.04 与 bash 5.0.17 . 问题造句:我将IntelliJ终端设置为/bin/bash通过 IntelliJ 设
给定如下命令: bash --shortcuts 我想显示一个快捷方式列表,就像在这个页面上一样: http://www.skorks.com/2009/09/bash-shortcuts-for-m
我有一个脚本可以操作数据、创建参数并将它们发送到第二个脚本。其中一个参数包含一个空格。 脚本1.sh: args=() args+=("A") args+=("1 2") args+=("B") .
我的脚本的“只运行一次”版本的一个非常简单的示例: ./myscript.sh var1 "var2 with spaces" var3 #!/bin/bash echo $1 #output: va
我想了解数字( double )在 bash 中是如何表示的,以及当我在 bash 中以十六进制格式打印数字时会发生什么。 根据 IEEE 754 标准,double 应由 64 位表示:52 位(1
我试图在 bash -c "..." 命令中获取 bash 脚本,但它不起作用。 如果我在 bash -c "..." 之外运行命令,它会起作用。 我需要使用 bash -c "..." 因为我想确保
如何检测我的 bash shell 中是否加载了 bash 补全包?从 bash-completion 的 2.1 版(包含在 Debian 8 中)开始,除了 BASH_COMPLETION_COM
我的 bash_profile 中有一个投影函数。现在我试图从 bash 脚本中调用这个函数,但是我得到了一个未找到的错误。如何使投影函数对 bash 脚本可见? 最佳答案 必须导出函数 export
我正在编写一个 bash 脚本,它接受许多命令行参数(可能包括空格)并通过登录 shell 将它们全部传递给程序 (/bin/some_program)。从 bash 脚本调用的登录 shell 将取
当我创建一个新的 bash 进程时,提示符默认为一个非常简单的提示符。我知道我可以编辑 .bashrc 等来更改它,但是有没有办法使用 bash 命令传递提示? 谢谢! 最佳答案 提示由 PS1、PS
好的,我希望这个问题有一定道理,但是 bash shell 和 bash 终端之间有什么区别?例子。当我第一次打开终端时,会提示我当前的目录和用户名。在终端窗口标题中显示 -bash- ,当我键入 e
我是 SBCL 的新手,我正在尝试从 bash 终端运行存储在文本文件中的 Lisp 脚本。 这是我在文件开头写的内容 http://www.sbcl.org/manual/#Running-from
我知道我们可以在 bash 中使用将十六进制转换为十进制 #!/bin/bash echo "Type a hex number" read hexNum echo $(( 16#$hexNum ))
我正在尝试在 bash 脚本中自动完成文件夹名称。如果我输入完整的文件夹名称,一切正常,但我不知道如何自动完成名称。有什么想法吗? repo() { cd ~/Desktop/_REPOS/$1 }
我想检查远程网站上的一些文件。 这里是bash命令生成计算文件md5的命令 [root]# head -n 3 zrcpathAll | awk '{print $3}' | xargs -I {}
是否有任何内置函数可以使用 bash shell 脚本从给定日期获取下周日(下周一、下周二等)?例如,2014 年 9 月 1 日之后的第一个星期日是什么时候?我预计 2014 年 9 月 7 日。
我一直在尝试根据表格重命名一些特定文件,但没有成功。它要么重命名所有文件,要么给出错误。 该目录包含数百个以长条形码命名的文件,我只想重命名包含模式 _1_ 的文件。 例子 barcode_1_bar
bash 中有没有办法用变量的内容替换文本文件中的占位符? 例如,我想发送一封电子邮件通知,如下所示: Dear Foo, Alert: blah blah blah blah blah blah
我有一个 bash 脚本,它在某些字符串上附加了一个重音字符,导致它失败,我找不到这些字符在哪里或如何进入那里。 这是一些示例输出: mv: cannot move â/tmp/myapp.zipâ
这个问题在这里已经有了答案: How do I place stdout on edit line? (1 个回答) Can a bash script prepopulate the prompt
我是一名优秀的程序员,十分优秀!