Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- void main ()
- {
- int filedes[2];
- if (pipe(filedes) == -1)
- {
- perror("Tworzenie potoku");
- exit(1);
- }
- switch(fork())
- {
- case -1: // blad w tworzeniu procesu
- perror("Tworzenie procesu");
- exit(1);
- case 0: // proces potomny
- if (write(filedes[1], "Hello world!", 12) == -1)
- {
- perror("Zapis do potoku");
- exit(1);
- }
- exit(0);
- default:
- {// proces macierzysty
- char buf[12];
- if (read(filedes[0], buf, 12) == -1)
- {
- perror("Odczyt z potoku");
- exit(1);
- }
- printf("Odczytano z potoku: %s\n", buf);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment