-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurrent_creat_fork.c
53 lines (51 loc) · 1.59 KB
/
concurrent_creat_fork.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include "simplefs.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define LEN 500000
#define NUM_OF_FILES 10
char msg[LEN];
int main() {
unlink("concurent_creat_fs");
simplefs_init("concurrent_creat_fs", 4096, 1024);
if(fork() == 0) {
int fsfd = simplefs_openfs("concurrent_creat_fs");
char name[10] = "/a00.txt";
int i = 0;
for(i = 0; i < NUM_OF_FILES; ++i) {
name[2] = '0' + i / 10;
name[3] = '0' + i % 10;
simplefs_creat(name, fsfd);
printf("US DZIEC %d", simplefs_unlink(name, fsfd));
}
sleep(1);
char drop[10] = "/b00.txt";
for(i = 0; i < NUM_OF_FILES; ++i) {
drop[2] = '0' + i / 10;
drop[3] = '0' + i % 10;
printf("try unlink %s child %d\n", drop, simplefs_unlink(drop, fsfd));
}
printf("dziecko koniec\n");
} else {
int fsfd = simplefs_openfs("concurrent_creat_fs");
char name[10] = "/b00.txt";
int i = 0;
for(i = 0; i < NUM_OF_FILES; ++i) {
name[2] = '0' + i / 10;
name[3] = '0' + i % 10;
simplefs_creat(name, fsfd);
printf("US OJC %d", simplefs_unlink(name, fsfd));
}
sleep(1);
char drop[10] = "/a00.txt";
for(i = 0; i < NUM_OF_FILES; ++i) {
drop[2] = '0' + i / 10;
drop[3] = '0' + i % 10;
printf("try unlink %s father %d\n", drop, simplefs_unlink(drop, fsfd));
}
printf("ojciec koniec\n");
}
return 0;
}