René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Pipes | ||
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main() { int pfds[2]; char buf[30]; pipe(pfds); if (!fork()) { printf(" CHILD: writing to the pipe\n"); write(pfds[1], "test", 5); printf(" CHILD: exiting\n"); exit(0); } else { printf("PARENT: reading from pipe\n"); read(pfds[0], buf, 5); printf("PARENT: read \"%s\"\n", buf); wait(NULL); } }
Die Ausgabe auf der Konsole:
PARENT: reading from pipe CHILD: writing to the pipe PARENT: read "test" CHILD: exiting |