SIGWINCH not delivered until letting go of resize window
Consider the below program. Now grab the terminal edge and resize by one column. Using the native OS X terminal, the signal gets fired after a short delay. In iterm2, the signal does not fire until resizing one more column or letting go of of the drag. I instrumented iterm2 and verified that the ioctl does indeed get issued at the correct time, it just doesn't arrive at the child process.
Interestingly, I tried writing an external file in the signal handler, just to check whether the signal handler was executed but something (e.g. the tty lock) was blocking it, but that didn't get written out until I stopped resizing the window completely.
I do not know OS X well enough to understand what is happening while resizing, so I'm hoping you might have an idea. OS version is 10.10.4.
/* demo_SIGWINCH.c
Demonstrate the generation of the SIGWINCH signal. A handler for SIGWINCH
allows the program to discover terminal window size changes; when that
signal is generated, the program displays the new terminal window size.
*/
#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
static void
sigwinchHandler(int sig)
{
}
int
main(int argc, char *argv[])
{
struct winsize ws;
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = sigwinchHandler;
if (sigaction(SIGWINCH, &sa, NULL) == -1)
_exit(2);
for (;;) {
pause(); /* Wait for SIGWINCH signal */
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1)
_exit(1);
printf("Caught SIGWINCH, new window size: "
"%d rows * %d columns\n", ws.ws_row, ws.ws_col);
}
}