Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char** argv) {
  7.     pid_t pid_potomka;
  8.     char *komunikat;
  9.     int powtorzen;
  10.     pid_t mojPid;
  11.     pid_t pidRodzica;
  12.     printf("Na razie dziala jeden proces\n");
  13.     pid_potomka = fork();
  14.     switch (pid_potomka) {
  15.         case -1:
  16.             printf("rozwidlenie procesu nie powiodlo sie\n");
  17.             exit(1);
  18.         case 0:
  19.             mojPid = getpid();
  20.             pidRodzica = getppid();
  21.             komunikat = "Jestem potomkiem";
  22.             powtorzen = 5;
  23.             break;
  24.         default:
  25.             komunikat = "Jestem rodzicem";
  26.             mojPid = getpid();
  27.             pidRodzica = getppid();
  28.             powtorzen = 5;
  29.             break;
  30.     }
  31.     for (; powtorzen > 0; powtorzen--) {
  32.         puts(komunikat);
  33.         printf("Moj: %d\n", mojPid);
  34.         printf("Rodzica: %d\n", pidRodzica);
  35.         sleep(1);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement