Can't change terminal size on pty/N (works on ttyN)

独自空忆成欢 提交于 2019-12-01 23:20:26

问题


I use the next to change terminal size:
rc = ioctl(fd, TIOCSWINSZ, &ws);
When I run this under linux text terminal (switching by Alt-Ctrl-F1), the result is that I expect to see. The whole my input and output within ranges given by ioctl syscall.
But when I connect to localhost by SSH, and run the same program, it works only partly. I mean that I can't input command wider than terminal size set by ioctl, but the output can cross the borders of terminal given by ioctl, and input can take more rows that set by ioctl. Also there is no auto carriage return and new line after that.
The only difference that I see when I run program directly it run on the terminal /dev/ttyN, and it's major number is 5, and when I run program via SSH it use /dev/pts/N as terminal, with major number 136. So, as I understood, it happens due the difference in terminals.
My questions:
1. Is that correct? Is the reason in terminal drivers?
2. How do I fix it? I need the same behaviour via SSH like in local tty terminal.

Thanks!


回答1:


Usually TIOCSWINSZ is used by the tty master (such as xterm, the Linux console itself, etc...) to tell the kernel driver how big the terminal actually is. The program running on the tty slave (i.e. the application itself) uses TIOCGWINSZ to query the size of the terminal. Most tty drivers don't support pushing it the other way; you can't in general call TIOCSWINSZ on the tty slave from the application and get the master to change its size.

Some terminals, such as xterm do support escape sequences to request them to resize, but this is just a byte escape sequence, and not an ioctl() command.

If you want the application to force the size of the terminal, then portably there is no way to do this. Unportably, you can apply a few special tricks like attempting TIOCSWINSZ or sending the xterm escape sequence.



来源:https://stackoverflow.com/questions/11483141/cant-change-terminal-size-on-pty-n-works-on-ttyn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!