一文搞懂 Linux TTY

TTY是电传打字机的简称,在Linux中用于键盘输入和显卡输出。`tty`命令显示当前终端名,而`stty`用于设置终端参数。Linux保留TTY支持多个控制台切换,如Ctrl+Alt+F1。伪终端(PTY)常用于远程登录和命令解释程序窗口,由/dev/ptmx创建,并受/proc/sys/kernel/pty/max限制。PTY在窗口系统和终端模拟器中扮演重要角色。
摘要由CSDN通过智能技术生成

TTY的历史

TTY全称TeleTYpewriter,也即是电传打字机,它通过两根电缆连接计算机,一根用于向计算机发送指令,一根用于接收计算机的输出,输出结果是打印在纸上的

由于历史原因, Linux保留了TTY,上述的输入和输出两个电缆,可以简单的认为是键盘输入和显卡输出

在这里插入图片描述

tty和stty命令

tty命令返回当前的终端名字,1表示可以通过Ctrl+Alt+F3得到

$ tty
/dev/pts/1

stty是对tty进行设置的命令,s表示set

  - Display all settings for the current terminal:
    stty -a

  - Set the number of rows:
    stty rows rows

  - Set the number of columns:
    stty cols cols

  - Get the actual transfer speed of a device:
    stty -F path/to/device_file speed

  - Reset all modes to reasonable values for the current terminal:
    stty sane

列出当前tty的所有配置信息:

$ 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最大配额

/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.

在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值