Revision: 967 Author: teawater Date: Mon Mar 12 07:33:23 2012 Log: Add new function to test code readc.c http://code.google.com/p/kgtp/source/detail?r=967 Modified: /bak/readc.c ======================================= --- /bak/readc.c Fri Oct 21 00:06:29 2011 +++ /bak/readc.c Mon Mar 12 07:33:23 2012 @@ -9,7 +9,9 @@ #include <sys/time.h> #include <signal.h> -static int read_count; +static unsigned long read_count; +static unsigned long read_all_count = 0; +static unsigned long read_times = 0; static void reset(void) @@ -28,11 +30,21 @@ } static void -handler(int signo) -{ - printf("%d\n", read_count); +handler_sigprof(int signo) +{ + read_all_count += read_count; + read_times++;+ printf("%d: %lu %lu\n", getpid(), read_count, read_all_count / read_times);
reset(); } + +static void +handler_sigint(int signo) +{ + printf("%lu\n", read_all_count / read_times); + read_all_count = 0; + read_times = 0; +} int main(int argc,char *argv[]) @@ -45,7 +57,7 @@ exit(-errno); } - act.sa_handler = handler; + act.sa_handler = handler_sigprof; if (sigfillset(&act.sa_mask) == -1) { perror("sigfillset"); exit(-errno); @@ -55,6 +67,11 @@ perror("sigaction"); exit(-errno); } + act.sa_handler = handler_sigint; + if (sigaction(SIGINT, &act, NULL) == -1) { + perror("sigaction"); + exit(-errno); + } reset();