关于伪终端的几点记录

下面引用自http://unix.stackexchange.com/questions/21280/difference-between-pts-and-tty的一段话

tty is a native terminal device, the backend is either hardware or kernel emulated.

pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xtermscreen, or ssh are such programs). pts is the slave part of a pty.

(More info can be found in man pty.)

Short résumé:

pty is created by a process through posix_openpt() (which usually opens the special device /dev/ptmx), and is constituted by a pair of bidirectional character devices:

  1. The master part, which is the file descriptor obtained by this process through this call, is used to emulate a terminal. After some initialization, the second part can be unlocked with unlockpt(), and the master is used to receive or send characters to this second part (slave).

  2. The slave part, which is anchored in the filesystem as /dev/pts/x (the real name can be obtained by the master through ptsname() ) behaves like a native terminal device (/dev/ttyx). In most cases, a shell is started that uses it as a controlling terminal.


    更为细致的描述,可参见《unix环境高级编程》关于终端登录、伪终端登录、伪终端描述那几章.......(以后再补上)

    Tips:通过了解原理后,我们可以限制远程登录用户:

    vim /etc/sysctl.conf
    增加
    kernel.pty.max = 5//限制伪终端为3个
    执行
    sysctl -p

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值