Advertisement
Forceisthop

Untitled

May 16th, 2022
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4.  
  5.  
  6. void main()
  7. {
  8.  
  9. pid_t pid;
  10. printf("Welcome");
  11. printf("Welcome");
  12. printf("\nMy process id:%d ParentProcessId:%d",getpid(),getppid());
  13. //printf("Welcome");
  14. printf("\n");
  15. pid=fork();
  16. if (pid > 0)
  17. {
  18. sleep(20);
  19. printf("\nI am parent");
  20. }
  21. else if (pid==0){
  22. printf("\nI am the child");
  23. printf("My process id:%d ParentProcessId:%d",getpid(),getppid());
  24. sleep(40);
  25. }
  26. else if(pid==-1)
  27. perror("\nfork");
  28. printf("\n");
  29. exit(0);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement