Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- int main() {
- int n;
- pid_t pid1 = fork();
- if (pid1==0){
- printf("Proces potomny %d\n",getpid());
- printf("podaj liczbe: ");
- scanf("%d", &n);
- for(int i = 0; i < n; i++){
- pid_t pid = fork();
- if(pid==0){
- printf("proces potomny potomka: %d %d \n", getpid(), getppid());
- exit(1);
- } else if(pid < 0){
- printf("ERROR");
- exit(1);
- }
- else{
- wait(NULL);
- }
- }
- }
- else if(pid1 < 0){
- printf("ERROR");
- exit(1);
- }
- else
- {
- printf("Proces rodzicielski %d\n",getpid());
- wait(NULL);
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement