简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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