简体   繁体   English

Shell如何在作业控制上恢复终端参数?

[英]How are terminal parameters restored by the shell on job control?

How is terminal state saved/restored when process is put in background and then in foreground again? 将进程置于后台然后再次置于前台时,如何保存/恢复终端状态? I'm reading https://www.gnu.org/software/libc/manual/html_node/Foreground-and-Background.html which gave me idea that tcgetattr/tcsetattr are responsible for this, but parameters like cursor configuration, alternate (cup) mode are not put in termios struct. 我正在阅读https://www.gnu.org/software/libc/manual/html_node/Foreground-and-Background.html ,这让我知道tcgetattr / tcsetattr对此负责,但是像游标配置这样的参数要交替使用( cup)模式不放在termios结构中。 I've managed to verify that with simple test code: 我设法用简单的测试代码验证了这一点:

struct termios t;
tcgetattr( 0, &t);
// change something
tcsetattr(0, TCSANOW, &t);

Or maybe process repaints terminal itself after being put in foreground with SIGCONT signal? 还是用SIGCONT信号将进程置于前台后重绘终端本身? I've tried to send it manually to some programs, but couldn't really tell if it repainted. 我尝试将其手动发送到某些程序,但无法真正判断它是否已重新绘制。

The tcgetattr() and tcsetattr() functions get and set the state of the terminal device . tcgetattr()tcsetattr()函数获取并设置终端设备的状态。 This includes options like baud rate, local echo, and translation of control characters to signals. 这包括波特率,本地回声以及将控制字符转换为信号之类的选项。 It does not include the state of the terminal emulator (or, possibly, the physical terminal!) on the remote end. 它不包括远程终端上的终端仿真器(或物理终端!)的状态。

Generally speaking, most applications which modify the terminal state enough that they'd interfere with the shell will trap ^Z and reset the terminal's state before backgrounding themselves. 一般而言,大多数对终端状态进行足够多修改以至于它们会干扰shell的应用程序都会捕获^ Z并在使自己进入后台之前重置终端的状态。 Additionally, most shells will reset the cursor's pen color and position when printing the prompt. 此外,大多数外壳将在打印提示时重置光标的笔颜色和位置。 Combined, these two factors are enough that it's not necessary for the kernel to get involved. 结合起来,这两个因素就足以使内核不必参与。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM