sieve exercise
This commit is contained in:
parent
61dc67b5d2
commit
aef3e0f5a4
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Homework: xv6</title>
|
||||
<title>Lab: xv6</title>
|
||||
<link rel="stylesheet" href="homework.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
@ -115,18 +115,10 @@ initial file system. You just ran one of them: <tt>ls</tt>.
|
|||
</pre>
|
||||
|
||||
<p>Optional: write an uptime program that prints the uptime in terms
|
||||
of ticks using the <tt>uptime</tt> system call.
|
||||
of ticks using the <tt>uptime</tt> system call.
|
||||
|
||||
<h2>pingpong</h2>
|
||||
|
||||
<p>In the previous exercise, if you made an error in sleep, the
|
||||
program may have exited prematurely, but it didn't affect other
|
||||
processes because xv6 isolates processes. Sometimes you want
|
||||
processes to interact with each other. Xv6 provides two ways to do:
|
||||
either through the file system (one process can create a file and
|
||||
another process can read that file) or through pipes. In this
|
||||
exercise you explore interprocess communication through pipes.
|
||||
|
||||
|
||||
<p> Write a program that uses UNIX system calls to ``ping-pong'' a
|
||||
byte between two processes over a pair of pipes, one for each
|
||||
direction. The parent sends by writing a byte to <tt>fd[1]</tt> and
|
||||
|
@ -140,6 +132,32 @@ initial file system. You just ran one of them: <tt>ls</tt>.
|
|||
<li>Use <tt>fork</tt> to create a child.
|
||||
<li>Use <tt>read</tt> to read from the pipe, and <tt>write</tt> to write to the pipe.
|
||||
</ul>
|
||||
|
||||
<h2>primes</h2>
|
||||
|
||||
<p>Write a concurrent version of prime sieve using pipes. This idea
|
||||
is due to Doug McIlroy, inventor of Unix pipes. The picture
|
||||
halfway down <a href="http://swtch.com/~rsc/thread/">the page</a>
|
||||
and the text surrounding it explain how to do it.
|
||||
|
||||
<p>Your goal is to use <tt>pipe</tt> and <tt>fork</tt> to set up
|
||||
the pipeline. The first process feeds the numbers 2 through 35
|
||||
into the pipeline. For each prime number, you will arrange to
|
||||
create one process that reads from its left neighbor over a pipe
|
||||
and writes to its right neighbor over another pipe. Since xv6 has
|
||||
limited number of file descriptors and processes, the first
|
||||
process can stop at 35.
|
||||
|
||||
<p>Some hints:
|
||||
<ul>
|
||||
<li>Be careful to close file descriptors that a process doesn't
|
||||
need, because otherwise your program will run xv6 out of resources
|
||||
before the first process reaches 35.
|
||||
|
||||
<li>Once the first process reach 35, you should arrange that the
|
||||
pipeline terminates cleanly (Hint: read will return an end-of-file
|
||||
when the write-side of the pipe is closed).
|
||||
</ul>
|
||||
|
||||
<h2>find</h2>
|
||||
|
||||
|
@ -161,6 +179,8 @@ initial file system. You just ran one of them: <tt>ls</tt>.
|
|||
</ul>
|
||||
|
||||
<h2>Optional: modify the shell</h2>
|
||||
|
||||
<p>Modify the shell to support wait.
|
||||
|
||||
<p>Modify the shell to support lists of commands, separated by ";"
|
||||
|
||||
|
|
Loading…
Reference in a new issue