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