Xv6 Labs 2024 Lab Util
This lab requires python<=3.12 (to import module
pipes
).
I’d like to record my process of implementing primes.c
.
At first, I didn’t know that subprocess who forked from the parent should close those opened files
(including pipes) of parent. The reason why we should close those is that fork()
replicates the
parent’s memory, and file descriptors.
File descriptors can be regarded as references, because each file descriptor as a four byte int (which is somehow a handle) corresponds to some file, which is implemented of reference counting technique.
However, as I closed the file descriptors, the program exited unexpectedly. I tested the program on
my Linux, and all of a sudden, the whole graphic session shut down. Realizing that the program shut
down due to the restricted number of process, I added error detection to fork()
, and the error had
eventually raised up. It could be confirmed that the error was from fork()
, due to the lack of
process resource.
So we should not let any possible error go. Keep guard!
I also learned from the util lab that stdin is just 0, and stdout is 1, and that stderr is 2.