|
@@ -1,4 +1,5 @@
|
|
//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 <string.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
|
|
int main()
|
|
int main()
|
|
@@ -6,18 +7,27 @@ int main()
|
|
|
|
|
|
int pid, pip[2];
|
|
int pid, pip[2];
|
|
char instring[20];
|
|
char instring[20];
|
|
|
|
+ char * outstring = "Hello World!";
|
|
|
|
|
|
- pipe(pip);
|
|
|
|
|
|
+ pipe(pip);
|
|
|
|
|
|
pid = fork();
|
|
pid = fork();
|
|
if (pid == 0) /* child : sends message to parent*/
|
|
if (pid == 0) /* child : sends message to parent*/
|
|
{
|
|
{
|
|
|
|
+ /* close read end */
|
|
|
|
+ close(pip[0]);
|
|
/* send 7 characters in the string, including end-of-string */
|
|
/* send 7 characters in the string, including end-of-string */
|
|
- write(pip[1], "Hi Mom!", 7);
|
|
|
|
|
|
+ write(pip[1], outstring, strlen(outstring));
|
|
|
|
+ /* close write end */
|
|
|
|
+ close(pip[1]);
|
|
}
|
|
}
|
|
else /* parent : receives message from child */
|
|
else /* parent : receives message from child */
|
|
{
|
|
{
|
|
|
|
+ /* close write end */
|
|
|
|
+ close(pip[1]);
|
|
/* read from the pipe */
|
|
/* read from the pipe */
|
|
read(pip[0], instring, 7);
|
|
read(pip[0], instring, 7);
|
|
|
|
+ /* close read end */
|
|
|
|
+ close(pip[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|