summaryrefslogtreecommitdiff
path: root/user/grind.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-11-07 06:44:23 -0500
committerRobert Morris <[email protected]>2019-11-07 06:44:23 -0500
commit20f1dd940964d7e01cf8c8d9b1a5b751840b7f3b (patch)
tree3aa0714040f24f35dad09f4cf9b7d4143a97b6f6 /user/grind.c
parent16b3b63f06c1ea17da484aeebea4a57fb2a6e44a (diff)
downloadxv6-labs-20f1dd940964d7e01cf8c8d9b1a5b751840b7f3b.tar.gz
xv6-labs-20f1dd940964d7e01cf8c8d9b1a5b751840b7f3b.tar.bz2
xv6-labs-20f1dd940964d7e01cf8c8d9b1a5b751840b7f3b.zip
more grind
Diffstat (limited to 'user/grind.c')
-rw-r--r--user/grind.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/user/grind.c b/user/grind.c
index 97a8a93..a01271e 100644
--- a/user/grind.c
+++ b/user/grind.c
@@ -48,13 +48,17 @@ rand(void)
}
void
-go()
+go(int which_child)
{
int fd = -1;
static char buf[999];
char *break0 = sbrk(0);
+ uint64 iters = 0;
while(1){
+ iters++;
+ if((iters % 500) == 0)
+ write(1, which_child?"B":"A", 1);
int what = rand() % 20;
if(what == 1){
close(open("a", O_CREATE|O_RDWR));
@@ -76,8 +80,12 @@ go()
read(fd, buf, sizeof(buf));
} else if(what == 9){
mkdir("a");
+ close(open("a/a", O_CREATE|O_RDWR));
+ unlink("a/a");
} else if(what == 10){
mkdir("b");
+ close(open("b/b", O_CREATE|O_RDWR));
+ unlink("b/b");
} else if(what == 11){
unlink("b");
link("a", "b");
@@ -88,6 +96,9 @@ go()
int pid = fork();
if(pid == 0){
exit(0);
+ } else if(pid < 0){
+ printf("grind: fork failed\n");
+ exit(1);
}
wait(0);
} else if(what == 14){
@@ -96,6 +107,9 @@ go()
fork();
fork();
exit(0);
+ } else if(pid < 0){
+ printf("grind: fork failed\n");
+ exit(1);
}
wait(0);
} else if(what == 15){
@@ -108,6 +122,9 @@ go()
if(pid == 0){
close(open("a", O_CREATE|O_RDWR));
exit(0);
+ } else if(pid < 0){
+ printf("grind: fork failed\n");
+ exit(1);
}
kill(pid);
wait(0);
@@ -116,8 +133,34 @@ go()
if(pid == 0){
kill(getpid());
exit(0);
+ } else if(pid < 0){
+ printf("grind: fork failed\n");
+ exit(1);
}
wait(0);
+ } else if(what == 19){
+ int fds[2];
+ if(pipe(fds) < 0){
+ printf("grind: pipe failed\n");
+ exit(1);
+ }
+ int pid = fork();
+ if(pid == 0){
+ fork();
+ fork();
+ if(write(fds[1], "x", 1) != 1)
+ printf("grind: pipe write failed\n");
+ char c;
+ if(read(fds[0], &c, 1) != 1)
+ printf("grind: pipe read failed\n");
+ exit(0);
+ } else if(pid < 0){
+ printf("grind: fork failed\n");
+ exit(1);
+ }
+ close(fds[0]);
+ close(fds[1]);
+ wait(0);
}
}
}
@@ -125,6 +168,9 @@ go()
int
main()
{
+ unlink("a");
+ unlink("b");
+
int pid1 = fork();
if(pid1 < 0){
printf("grind: fork failed\n");
@@ -132,7 +178,7 @@ main()
}
if(pid1 == 0){
rand_next = 31;
- go();
+ go(0);
exit(0);
}
@@ -143,7 +189,7 @@ main()
}
if(pid2 == 0){
rand_next = 7177;
- go();
+ go(1);
exit(0);
}