Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <errno.h>
- #define N_PROC
- int main() {
- pid_t pid;
- int i;
- printf("Moj PID to = %d \n", getpid());
- for (i=1; i<=N_PROC; i++) switch(pid=fork())
- { case -1:
- printf("Error in fork = %d %s\n",errno,strerror(errno));
- case 0: printf("Jestem procesem potomnym. Mój PID = %d\n",getpid());
- printf("Jestem procesem potomnym wartość przez fork() = %d\n",pid);
- return 0;
- default: printf("Jestem procesem macierzystym. Mój PID = %d\n",getpid());
- printf("Jestem procesem macierzystym wartość przez fork() = %d\n",pid);
- }
- //sleep(10);
- for (i=1; i<=N_PROC; i++) if(wait(0)==-1)
- printf("Error in wait = %d %s\n",errno,strerror(errno));
- return 0; } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement