Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #define N 2
- void macierzysty()
- {
- int i;
- for(i=1;i<=N;i++)
- {
- printf("+++Proces macierzysty i=%d\n", i);
- }
- printf("+++Proces macierzysty zakonczony\n");
- //if(wait(0) == -1){printf("def Error in fork = %d %s", errno, strerror(errno));}
- }
- void potomny()
- {
- int j;
- for(j=1;j<=N;j++)
- {
- printf("---Proces potomny j=%d\n", j);
- }
- printf("---Proces potomny zakonczony\n");
- }
- int main()
- {
- int liczba;
- switch(liczba = fork())
- {
- case -1: printf("Error in fork = %d %s\n", errno, strerror(errno));
- case 0: potomny();
- return 0;
- default :
- macierzysty();
- waitpid(0);
- if(wait(0) == -1){printf("def Error in fork = %d %s", errno, strerror(errno));}
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement