General description:
this program demonstrates how a the CPU’s context-switch mechanism works. It starts by running code that will specify the use of only ONE cpu core. Then, it will fork into the parent and the child which use pipes to communicate within each other. Because the child and the parent read and write to each other they must wait for each other’s input. It’s in Scenarios like these that the context switch happens. And in this program it is demonstrated by the printed output by the child and the parent respectively.
Effective Use for Learning:
Try reading the code and predicting the output of it before running it. Then, uncomment line 82 and predict what would happen again.