Penguin
Annotated edit history of SIGWINCH version 4, including all changes. View license author blame.
Rev Author # Line
1 PerryLorier 1 !!!Signal: __Win__dow size __Ch__ange
2
4 JohnMcPherson 3 This signal is delivered to a process when its terminal size changes. The default action is to ignore the signal. Usually a process that cares about displaying information on the screen would use the resize information to redraw the screen and update its idea of how large the screen is.
2 PerryLorier 4
4 JohnMcPherson 5 Now, the real question here, is how do you know what the new size of the screen is? the answer is the TIOCGWINSZ ioctl(2).
2 PerryLorier 6
7 an example:
4 JohnMcPherson 8 <verbatim>
2 PerryLorier 9 #include <termios.h>
10 #include <sys/ioctl.h>
11 #include <fcntl.h>
12 #include <stdio.h>
13
14 int main(int argc,char **argv)
15 {
16 struct winsize ws;
17 int fd=open("/dev/tty",O_RDWR);
18
19 if (ioctl(fd,TIOCGWINSZ,&ws)!=0) {
20 perror("ioctl(/dev/tty,TIOCGWINSZ)");
21 return 1;
22 }
23 printf("rows %i\n",ws.ws_row);
24 printf("cols %i\n",ws.ws_col);
25 return 0;
26 }
4 JohnMcPherson 27 </verbatim>
28
29 If bash(1) (or zsh(1)...) is the terminal's controlling process when a terminal is resized, it will automatically update the ''$LINES'' and ''$COLUMNS'' variables.
30
3 JohnMcPherson 31
4 JohnMcPherson 32 My xterm sometimes dies if I resize it while [IRC] is running in it. Presumably, what's happening is that during the resize, the irc client tries to write to the bottom of the xterm and the signal from xterm doesn't get handled in time, causing my xterm (version 156) to "disappear" when the ncurses(3x) library tries to write to a bit of the xterm that's no longer there.