Facebook
From Blush Eider, 3 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 43
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/wait.h>
  4.  
  5. int main(){
  6.  
  7.         int Liczba;
  8.         int ChildPid;
  9.         int i;
  10.  
  11.         printf(" Proces macierzysty pid(%d)\n", getpid());
  12.         if((ChildPid=fork()) == 0){
  13.                 sleep(2);
  14.                 for(i=0; i<5; i++){
  15.                         printf("\n Proces potomny pid(%d), i=%d", getpid(), i);
  16.                         sleep(2);
  17.                 }
  18.                 printf("\n Proces potomny pid(%d) --> operacja zakonczenie\n", getpid());
  19.                 exit(0);
  20.         }
  21.         printf("\n Proces macierzysty pid(%d) --> Czekam na zakonczenie procesu potomnego pid(%d)", getpid(), ChildPid);
  22.         wait(0);
  23.         printf("\n Proces macierzysty pid(%d) --> Proces potomny zostal zakonczony pid(%d)", getpid(), ChildPid);
  24.         printf("\n");
  25. }