Exercise 1
Last updated
Was this helpful?
Last updated
Was this helpful?
After tryingpipe_creation.c
,pipe_withfork.c
andpipe_withfork2.c
, you should be able to answer questionsQ1-6. According toQ4, we know that when pipe is empty, the reader process blocks until writer process write something into pipe. Similarly, when pipe is full. the writer process blocks until reader process reads something from pipe.use this property to synchronize processes. Inpipe-ex1.c
, parent and child processes need communicate with each other according to the following rules:
Parent sends a message (a character "p") to child.
Child sends acknowledgment message (a character "c") to parent on receiving "p", otherwise, child waits and does nothing.
When parent receives "c", it sends the next "p" to child, otherwise, parent waits and does nothing.
Beforefork()
, we create two pipes as shown in the following figure. Parent writes the character "p" across the top pipe when TELL_CHILD is called, child writes "c" across the bottom pipe when TELL_PARENT is called.
Exercise-1 Complete TELL\_PARENT
,TELL\_CHILD
,WAIT\_PARENT
,WAIT\_CHILD
to make parent and child communicate correctly. That is to say,pipe-ex1.cshould output as below.