#include #include #include #include #include void winhand(int sig) { struct winsize ws; ioctl(0,TIOCGWINSZ,&ws); printf("%d x %d\n",ws.ws_col,ws.ws_row); } #if 0 struct winsize { unsigned short ws_row; /* rows, in characters */ unsigned short ws_col; /* columns, in characters */ unsigned short ws_xpixel; /* horizontal size, pixels */ unsigned short ws_ypixel; /* vertical size, pixels */ }; TIOCGWINSZ struct winsize *ws Put the window size information associated with the terminal in the winsize structure pointed to by ws. The window size structure contains the number of rows and columns (and pixels if appropriate) of the devices attached to the terminal. It is set by user software and is the means by which most full-screen oriented programs determine the screen size. The winsize structure is defined in . #endif int main(int argc,char *argv[]) { winhand(SIGWINCH); signal(SIGWINCH,winhand); while(1) { sleep(100); } }