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. I've managed to verify that with simple test code:
当进程被放置在后台,然后再次放置在前台时,如何保存/恢复终端状态?我正在阅读https://www.gnu.org/software/libc/manual/html_node/foreground -and- back .html,这让我想到tcgetattr/tcsetattr应该对此负责,但是游标配置、备用(cup)模式等参数没有使用termios struct。我通过简单的测试代码验证了这一点:
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? I've tried to send it manually to some programs, but couldn't really tell if it repainted.
或者用SIGCONT信号将终端本身放到前台后再重新绘制?我试过手动发送给一些程序,但是不能确定它是否重新绘制。
1 个解决方案
#1
3
The tcgetattr()
and tcsetattr()
functions get and set the state of the terminal device. 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.
tcgetattr()和tcsetattr()函数获取并设置终端设备的状态。这包括诸如波特率、本地回波和将控制字符转换为信号等选项。它不包含远程端上的终端模拟器(或者可能是物理终端!)的状态。
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. 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.
一般来说,大多数应用程序,修改终端状态,以至于他们会干扰^ Z shell将陷阱和重置终端后台处理自己之前的状态。此外,在打印提示符时,大多数shell将重置光标的笔色和位置。结合起来,这两个因素就足够了,内核不需要参与进来。
#1
3
The tcgetattr()
and tcsetattr()
functions get and set the state of the terminal device. 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.
tcgetattr()和tcsetattr()函数获取并设置终端设备的状态。这包括诸如波特率、本地回波和将控制字符转换为信号等选项。它不包含远程端上的终端模拟器(或者可能是物理终端!)的状态。
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. 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.
一般来说,大多数应用程序,修改终端状态,以至于他们会干扰^ Z shell将陷阱和重置终端后台处理自己之前的状态。此外,在打印提示符时,大多数shell将重置光标的笔色和位置。结合起来,这两个因素就足够了,内核不需要参与进来。