11 int main(int argc, char *argv[])
14 unsigned long count, i;
19 if (argc < 3 || argc > 4) {
20 fprintf(stderr, "usage: %s <filename> <iterations> [threads]\n",
25 count = strtoul(argv[2], NULL, 0);
27 threads = strtoul(argv[3], NULL, 0);
29 for (i = 1; i <= threads; i++) {
32 fprintf(stderr, "error: %s: #%ld - %s\n", argv[0], i,
33 strerror(rc = errno));
40 printf("%s: thread #%ld (PID %d) started\n",
45 if (threads && thread == 0) { /* parent process */
46 int live_threads = threads;
48 while (live_threads > 0) {
52 ret = waitpid(0, &status, 0);
58 fprintf(stderr, "error: %s: wait - %s\n",
59 argv[0], strerror(errno));
64 * This is a hack. We _should_ be able to use
65 * WIFEXITED(status) to see if there was an
66 * error, but it appears to be broken and it
67 * always returns 1 (OK). See wait(2).
69 int err = WEXITSTATUS(status);
70 if (err || WIFSIGNALED(status))
72 "%s: PID %d had rc=%d\n",
81 for (i = 0; i < count; i++) {
83 sprintf(filename, "%s-%d-%ld",
86 sprintf(filename, "%s-%ld", argv[1], i);
88 rc = mknod(filename, S_IFREG, 0);
90 fprintf(stderr, "mknod(%s): %s\n",
91 filename, strerror(errno));
95 if (unlink(filename) < 0) {
96 fprintf(stderr, "unlink(%s): %s\n",
97 filename, strerror(errno));
103 printf("Thread %d done: rc = %d\n", thread, rc);
105 printf("Done: rc = %d\n", rc);