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);
48 write(1, "\033[4;0H", 6);
50 for (i
= 0; i
< argc
; i
++)
52 printf("Arg. %d: %s\n", i
, argv
[i
]);
57 gettimeofday(&tv1
, 0);
58 write(1, "\033[30;41m", 8);
59 write(1, "fork()! \n", 15);
60 for (i
= 0; i
< 1000; i
++)
69 write(1, "DONE! \n", 15);
72 gettimeofday(&tv2
, 0);
73 printf("%d seconds (%d).\n", time2
- time1
, time2
);
75 if (tv1
.tv_usec
> tv2
.tv_usec
)
77 tv2
.tv_usec
+= 1000000;
80 int difference
= tv2
.tv_usec
/ 1000 - tv1
.tv_usec
/ 1000 + tv2
.tv_sec
* 1000 - tv1
.tv_sec
* 1000;
81 write(1, "\033[7;0H", 6);
82 printf("%d seconds.\n", difference
);
85 while ((c
= getchar()) != 'q')