|
@@ -1,5 +1,4 @@
|
|
//http://www2.cs.uregina.ca/~hamilton/courses/330/notes/unix/pipes/pipes.html
|
|
//http://www2.cs.uregina.ca/~hamilton/courses/330/notes/unix/pipes/pipes.html
|
|
-#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
|
|
@@ -15,25 +14,19 @@ int main()
|
|
pid = fork();
|
|
pid = fork();
|
|
if (pid == 0) /* child : sends message to parent*/
|
|
if (pid == 0) /* child : sends message to parent*/
|
|
{
|
|
{
|
|
- puts("Child: Close Read");
|
|
|
|
/* close read end */
|
|
/* close read end */
|
|
close(pip[0]);
|
|
close(pip[0]);
|
|
- puts("Child: Write");
|
|
|
|
/* send 7 characters in the string, including end-of-string */
|
|
/* send 7 characters in the string, including end-of-string */
|
|
write(pip[1], outstring, strlen(outstring));
|
|
write(pip[1], outstring, strlen(outstring));
|
|
- puts("Child: Close Write");
|
|
|
|
/* close write end */
|
|
/* close write end */
|
|
close(pip[1]);
|
|
close(pip[1]);
|
|
}
|
|
}
|
|
else /* parent : receives message from child */
|
|
else /* parent : receives message from child */
|
|
{
|
|
{
|
|
- puts("Parent: Close Write");
|
|
|
|
/* close write end */
|
|
/* close write end */
|
|
close(pip[1]);
|
|
close(pip[1]);
|
|
- puts("Parent: Read");
|
|
|
|
/* read from the pipe */
|
|
/* read from the pipe */
|
|
read(pip[0], instring, 7);
|
|
read(pip[0], instring, 7);
|
|
- puts("Parent: Close Read");
|
|
|
|
/* close read end */
|
|
/* close read end */
|
|
close(pip[0]);
|
|
close(pip[0]);
|
|
}
|
|
}
|