12 #define O_DIRECT 040000 /* direct disk access hint */
15 int main(int argc, char *argv[])
18 unsigned long count, i;
24 if (argc < 3 || argc > 4) {
25 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
30 count = strtoul(argv[2], NULL, 0);
32 threads = strtoul(argv[3], NULL, 0);
34 for (i = 1; i <= threads; i++) {
37 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
38 strerror(rc = errno));
45 printf("%s: thread #%ld (PID %d) started\n",
50 if (threads && thread == 0) { /* parent process */
51 int live_threads = threads;
53 while (live_threads > 0) {
57 ret = waitpid(0, &status, 0);
63 fprintf(stderr, "error: %s: wait - %s\n",
64 argv[0], strerror(errno));
69 * This is a hack. We _should_ be able to use
70 * WIFEXITED(status) to see if there was an
71 * error, but it appears to be broken and it
72 * always returns 1 (OK). See wait(2).
74 int err = WEXITSTATUS(status);
75 if (err || WIFSIGNALED(status))
77 "%s: PID %d had rc=%d\n",
87 sprintf(filename, "%s-%d", argv[1], thread);
89 strcpy(filename, argv[1]);
91 fd = open(filename, O_RDWR|O_CREAT, 0644);
93 fprintf(stderr, "open(%s, O_CREAT): %s\n", filename,
98 fprintf(stderr, "close(): %s\n", strerror(errno));
103 for (i = 0; i < count; i++) {
104 fd = open(filename, O_RDWR|O_LARGEFILE|O_DIRECT);
106 fprintf(stderr, "open(%s, O_RDWR): %s\n",
107 filename, strerror(errno));
112 fprintf(stderr, "close(): %s\n",
119 if (unlink(filename) < 0) {
120 fprintf(stderr, "unlink(%s): %s\n", filename,
125 printf("Thread %d done: rc = %d\n", thread, rc);
127 printf("Done: rc = %d\n", rc);