本文最后更新于:2022年9月4日 下午
TTY的历史
TTY全称TeleTYpewriter
,也即是电传打字机,它通过两根电缆连接计算机,一根用于向计算机发送指令,一根用于接收计算机的输出,输出结果是打印在纸上的
由于历史原因, Linux保留了TTY,上述的输入和输出两个电缆,可以简单的认为是键盘输入和显卡输出
tty和stty命令
tty命令返回当前的终端名字,1表示可以通过Ctrl+Alt+F3得到
stty是对tty进行设置的命令,s表示set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| - Display all settings for the current terminal: stty -a
- Set the stty
- Set stty
- Get stty /to/
- Reset stty
|
列出当前tty的所有配置信息:
1 2 3 4 5 6 7 8
| $ stty -a speed 9600 baud; rows 35; columns 129; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
|
切换tty
Ctrl+Alt+F1可以切换到第一个tty,以此类推
这里把字符串输入到tty2,由于现在处于pts1,因此终端没有显示,当切换到tty2就会显示字符串
这里切换到了tty4
伪终端:pseudo terminal
- 终端模拟器(terminal emulator) ,是运行在内核的模块
- 用户态的终端模拟程序,被称为伪终端(pseudo terminal, PTY)
可以通过打开文件 /dev/ptmx 创建伪终端,伪终端 pty 具有以下两种用途:
- 使用 telnet、 ssh 命令支持远程登录
- 提供窗口系统用以创建命令解释程序窗口的界面
pty最大配额
1 2 3 4 5 6
| /proc/sys/kernel/pty/max This file defines the maximum number of pseudoterminals.
/proc/sys/kernel/pty/nr This read-only file indicates how many pseudoterminals are currently in use.
|