![一个进程正在打开 tty,但“ps t tty”看不到它](https://linux22.com/image/1512160/%E4%B8%80%E4%B8%AA%E8%BF%9B%E7%A8%8B%E6%AD%A3%E5%9C%A8%E6%89%93%E5%BC%80%20tty%EF%BC%8C%E4%BD%86%E2%80%9Cps%20t%20tty%E2%80%9D%E7%9C%8B%E4%B8%8D%E5%88%B0%E5%AE%83.png)
请参阅以下示例:
[STEP 101] # tty
/dev/pts/3
[STEP 102] # ssh -f -n -N -D :7070 127.0.0.1
[STEP 103] # pgrep -lf 7070
33109 ssh
[STEP 104] # ls -l /proc/33109/fd/
total 0
lrwx------ 1 root root 64 2016-11-08 10:45 0 -> /dev/pts/3
lrwx------ 1 root root 64 2016-11-08 10:45 1 -> /dev/pts/3
lrwx------ 1 root root 64 2016-11-08 10:45 2 -> /dev/pts/3
lrwx------ 1 root root 64 2016-11-08 10:45 3 -> socket:[3328390]
lrwx------ 1 root root 64 2016-11-08 10:45 4 -> socket:[3328441]
[STEP 105] # ps t pts/3
PID TTY STAT TIME COMMAND
33115 pts/3 R+ 0:00 ps t pts/3
66586 pts/3 Ss 0:08 /root/bin/bash
[STEP 106] #
在步骤 104它显示该ssh
过程正在打开pts/3
,但为什么ps t pts/3
命令步骤 105看不到?
答案1
根据ps
手册:
t ttylist
Select by tty. Nearly identical to -t and --tty, but can also
be used with an empty ttylist to indicate the terminal
associated with ps. Using the T option is considered cleaner
than using t with an empty ttylist.
这里 ”通过 tty 选择“原来意思是”选择控制 tty“。并将ssh -f
作为没有控制 tty. 查看输出步骤 111在以下示例中:
[STEP 107] # tty
/dev/pts/28
[STEP 108] # ssh -D :7070 -f -n -N 127.0.0.1
[STEP 109] # pgrep -lf 7070
72531 ssh
[STEP 110] # ls -l /proc/72531/fd
total 0
lrwx------ 1 root root 64 2016-11-16 17:47 0 -> /dev/pts/28
lrwx------ 1 root root 64 2016-11-16 17:47 1 -> /dev/pts/28
lrwx------ 1 root root 64 2016-11-16 17:47 2 -> /dev/pts/28
lrwx------ 1 root root 64 2016-11-16 17:47 3 -> socket:[3572721]
lrwx------ 1 root root 64 2016-11-16 17:47 4 -> socket:[3572770]
[STEP 111] # ps p 72531 j
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 72531 72531 72531 ? -1 Ss 0 0:00 ssh -D :7070 -f -n -N 127.0.0.1
[STEP 112] #