14 void size_changed(int sig
)
17 int status
= ioctl(0, TIOCGWINSZ
, &size
);
21 snprintf(tmp
, 30, "\033[%d;%dH", size
.ws_row
, size
.ws_col
);
22 write(1, tmp
, strlen(tmp
));
27 int main(int argc
, char **argv
)
29 signal(SIGWINCH
, size_changed
);
31 write(1, "\033[2J", 4);
32 write(1, "\033[0;0H", 6);
33 write(1, "\033[30;41m", 8);
34 write(1, "Hello ", 6);
35 write(1, "\033[33;40m", 8);
36 write(1, "World!\n", 7);
39 int status
= ioctl(0, TIOCGWINSZ
, &size
);
42 write(1, "\033[37;40m", 8);
43 printf("Size: %d/%d.\n", size
.ws_row
, size
.ws_col
);
44 write(1, "\033[53;180H", 9);
50 gettimeofday(&tv1
, 0);
51 write(1, "\033[30;41m", 8);
52 write(1, "\033[4;0H", 6);
53 write(1, "fork()! ", 14);
55 for (i
= 0; i
< 1000; i
++)
64 write(1, "\033[5;0H", 6);
65 write(1, "DONE! ", 14);
68 gettimeofday(&tv2
, 0);
69 write(1, "\033[6;0H", 6);
70 printf("%d seconds (%d).\n", time2
- time1
, time2
);
72 if (tv1
.tv_usec
> tv2
.tv_usec
)
74 tv2
.tv_usec
+= 1000000;
77 int difference
= tv2
.tv_usec
/ 1000 - tv1
.tv_usec
/ 1000 + tv2
.tv_sec
* 1000 - tv1
.tv_sec
* 1000;
78 write(1, "\033[7;0H", 6);
79 printf("%d seconds.\n", difference
);
82 while ((c
= getchar()) != 'q')