5-1 Bash进程与终端

什么是终端 能实现数据输入、输出的统称为终端。 物理终端:传统显示器、键盘,通过 VGA、HDMI、USB 等连接。 软件终端(虚拟终端/伪终端):通过 TCP/IP 协议实现的终端,能模拟出来一个实现「数据输入、输出」的终端,比如:ssh、telnet … 这篇博客介绍的比较详细:「转」彻底理解Linux的各种终端类型以及概念。 伪终端的连接过程 在linux中有物理终端,有虚拟终端(伪终端)。 sshd 服务会打开一个 [dev/ptmx],这个文件是一个伪终端主设备文件。 bin/bash 会打开一个 dev/pts(0,1…), 是一个伪终端从设备文件。 ptmx/ptsx 它们通过伪终端设备驱动程序模拟出输入和输出的功能。 bin/bash 进程就可以实现数据读取和数据写入。 ssh客户端 ——————> 远程服务器的一个进程 ——-> ssh客户端。 输入单元(ssh客户端)——–> /bin/bash进程————–> 输出单元(ssh客户端)。 bin/bash 启动之后,对终端数据的读取和写入就是通过 pts 实现的(能实现标准输入,标准输出)。 dev/pts0 0 1 2 标准输入,标准输出,标准错误。 通过 strace 命令查看sshd服务: strace 前进程关系: ├─sshd,9408 │ └─sshd,2888142 │ └─bash,2888170 │ └─pstree,2889779 -ap strace 中: $strace -f -s 65500 -o sshd.log -p 9408 # strace 查看系统调用,进行一个新的 SSH 连接 strace: Process 9408 attached strace: Process 2888330 attached strace: Process 2888331 attached strace: Process 2888336 attached strace: Process 2888342 attached strace: Process 2888343 attached strace: Process 2888344 attached strace: Process 2888345 attached strace: Process 2888346 attached strace: Process 2888347 attached strace: Process 2888348 attached strace: Process 2888349 attached strace: Process 2888350 attached strace: Process 2888351 attached strace: Process 2888352 attached strace: Process 2888353 attached strace: Process 2888354 attached strace: Process 2888355 attached strace: Process 2888356 attached strace: Process 2888357 attached # 新的SSH连接 strace: Process 2888358 attached strace: Process 2888359 attached strace: Process 2888360 attached strace: Process 2888361 attached strace: Process 2888362 attached strace: Process 2888363 attached strace: Process 2888364 attached strace: Process 2888365 attached strace: Process 2888382 attached ^Cstrace: Process 9408 detached # 终止信号 strace: Process 2888330 detached strace: Process 2888357 detached 新的 SSH 连接以后的进程关系:...

2022-03-16 · 王二