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 procfor 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
eaxin the killed process.
What's a better idea? (or less worse)
The definite answer is no, the purpose of
eaxis 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 oneaxafter akill()as you never know when the kernel will actually kill the process.