17 static int create_files(int dir, int nfiles)
21 asprintf(&dname, "dir%d", dir);
23 if (mkdir(dname, 0755) != 0 && errno != EEXIST) {
28 for (i=0;i<nfiles;i++) {
30 asprintf(&fname, "%s/File%d", dname, i);
31 fd = open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);
36 write(fd, fname, strlen(fname)+1);
44 static int check_files(int dir, int nfiles)
48 asprintf(&dname, "dir%d", dir);
50 for (i=0;i<nfiles;i++) {
53 asprintf(&fname, "%s/File%d", dname, i);
54 fd = open(fname, O_RDONLY, 0644);
59 read(fd, s, sizeof(s));
62 if (strcmp(fname, s)) {
63 printf("Name mismatch! %s %s\n", fname, s);
70 if (rmdir(dname) != 0) {
77 int main(int argc, char *argv[])
79 int nprocs, nfiles, i, ret=0, status;
81 nprocs = atoi(argv[1]);
82 nfiles = atoi(argv[2]);
84 printf("Creating %d files in %d dirs\n", nfiles, nprocs);
86 for (i=0;i<nprocs;i++) {
88 exit(create_files(i, nfiles));
92 while (waitpid(0, &status, 0) > 0 || errno != ECHILD) {
93 if (WEXITSTATUS(status) != 0) {
94 ret = WEXITSTATUS(status);
95 printf("Child exited with status %d\n", ret);
99 for (i=0;i<nprocs;i++) {
101 exit(check_files(i, nfiles));
105 while (waitpid(0, &status, 0) > 0 || errno != ECHILD) {
106 if (WEXITSTATUS(status) != 0) {
107 ret = WEXITSTATUS(status);
108 printf("Child exited with status %d\n", ret);