I'm taking OS class and we need to extend XV6's exit()
to support exit status, thus we're writing exit2(int)
.
I thought of two candidates for the purpose of saving the exit status of the killed process.
The first option was to add a variable to
struct proc
for exit status. My problem with this solution is that it involves changing a fundamental structure of the OS for a very little cause, and moreover it means I'm gonna have a garbage integer for every process, which is not the best idea.Second idea was to save the exit status in a trap frame register of the killed process, but then I have something inside me saying that I should not trust the value of
eax
in the killed process.
What's a better idea? (or less worse)
The definite answer is no, the purpose of
eax
is to be used as a return value from procedures. In some kernel implementations (I know it works on rev 6 of xv6) this trick MIGHT work but one can not rely oneax
after akill()
as you never know when the kernel will actually kill the process.