Advertisement
Guest User

fsafas

a guest
Jan 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. //
  5. int main(){
  6. pid_t grandpa_pid = getpid();
  7. pid_t child_pid;
  8. if ((child_pid = fork()) == 0){
  9. pid_t parent_pid = getpid();
  10. pid_t child_child_pid;
  11. if ((child_child_pid = fork()) == 0) {
  12. usleep(200);
  13. printf("Procesul nepot cu pid %d, pid copil %d , pid nepot %d .", getpid(), parent_pid, grandpa_pid);
  14. } else {
  15. usleep(100);
  16. printf("Procesul copil cu pid %d, pid nepot %d , pid parinte %d .", getpid(), child_child_pid, grandpa_pid);
  17. }
  18. } else {
  19. printf("Procesul parinte cu pid %d si pid copil %d.", getpid(), child_pid);
  20. }
  21. printf("\n");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement