cleanup zombies during run, and check processes still exist
[tridge/junkcode.git] / create_loop.c
1 #include <stdio.h>
2 #include <sys/time.h>
3 #include <time.h>
4 #include <errno.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8
9 static struct timeval tp1,tp2;
10
11 static void start_timer()
12 {
13         gettimeofday(&tp1,NULL);
14 }
15
16 static double end_timer()
17 {
18         gettimeofday(&tp2,NULL);
19         return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) - 
20                 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
21 }
22
23
24 static void create_loop(const char *fname)
25 {
26         unsigned count = 0;
27         int fd;
28         start_timer();
29
30         while (1) {
31                 count++;
32
33                 unlink(fname);
34                 fd = open(fname, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0644);
35                 if (fd == -1) {
36                         perror(fname);
37                         exit(1);
38                 }
39                 close(fd);
40
41                 if (end_timer() > 1.0) {
42                         printf("%.0f ops/sec\r", count/end_timer());
43                         fflush(stdout);
44                         start_timer();
45                         count=0;
46                 }
47         }
48 }
49
50 static void usage(void)
51 {
52         printf("usage: create_loop <file>\n");
53 }
54
55 int main(int argc, char *argv[])
56 {
57         if (argc < 2) {
58                 usage();
59                 exit(1);
60         }
61         create_loop(argv[1]);
62         return 0;
63 }