diff options
author | rtm <rtm> | 2006-07-11 17:39:45 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-11 17:39:45 +0000 |
commit | b548df152b5a53ea8cfcb2d94fbdee07884d8050 (patch) | |
tree | b1eec270a0892fad7a256ae809ebedbbcfaeb720 /usertests.c | |
parent | 5ce9751cab960e3b226eb0720e781e793a0be4ed (diff) | |
download | xv6-labs-b548df152b5a53ea8cfcb2d94fbdee07884d8050.tar.gz xv6-labs-b548df152b5a53ea8cfcb2d94fbdee07884d8050.tar.bz2 xv6-labs-b548df152b5a53ea8cfcb2d94fbdee07884d8050.zip |
pre-empt both user and kernel, in clock interrupt
usertest.c tests pre-emption
kill()
Diffstat (limited to 'usertests.c')
-rw-r--r-- | usertests.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/usertests.c b/usertests.c index 37540db..2f688ca 100644 --- a/usertests.c +++ b/usertests.c @@ -1,7 +1,7 @@ -// simple fork and pipe read/write - char buf[2048]; +// simple fork and pipe read/write + void pipe1() { @@ -47,9 +47,54 @@ pipe1() puts("pipe1 ok\n"); } +// meant to be run w/ at most two CPUs +void +preempt() +{ + int pid1, pid2, pid3; + int pfds[2]; + + pid1 = fork(); + if(pid1 == 0) + while(1) + ; + + pid2 = fork(); + if(pid2 == 0) + while(1) + ; + + pipe(pfds); + pid3 = fork(); + if(pid3 == 0){ + close(pfds[0]); + if(write(pfds[1], "x", 1) != 1) + puts("preempt write error"); + close(pfds[1]); + while(1) + ; + } + + close(pfds[1]); + if(read(pfds[0], buf, sizeof(buf)) != 1){ + puts("preempt read error"); + return; + } + close(pfds[0]); + kill(pid1); + kill(pid2); + kill(pid3); + wait(); + wait(); + wait(); + puts("preempt ok\n"); +} + main() { + puts("usertests starting\n"); pipe1(); + //preempt(); while(1) ; |