Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/wait.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6. int main (void){
  7. pid_t pid;
  8. pid_t childid;
  9. pid_t parentid;
  10. int fab1=0,fab2=1,fab3,i,num;
  11. printf("Enter a number");
  12. scanf("%d",&num);
  13. pid=fork();
  14. if (pid == 0){
  15. childid=getpid();
  16. parentid=getppid();
  17. printf("\n The parent process id is: %d\n, ",parentid);
  18. printf("%d,%d,",fab1,fab2);
  19.  
  20. for(i=2;i<=num;++i){
  21. fab3=fab1+fab2;
  22. printf("%d,",fab3);
  23. fab1=fab2;
  24. fab2=fab3;
  25. }
  26. printf("\n");
  27. exit(0);
  28. }
  29. else if (pid > 0){
  30. int x;
  31. sleep(10);// meken wenne when parrent process eka sleep krn ekaa child process eka end weddii parent is sleeping so there is no way to catch the child process ID, process table ekta ynwa blah blah blah change th
  32. // x=wait (NULL);parent process eka child process eka end wenkn htiye ntm eka process table eken ain wenne na, hence zombie process. meke wait eke commente, un commnet knre nathuwa change the comment so that u can justify
  33. printf ("Child Process ID is : %d",x);
  34. }
  35. return 0;
  36. }
  37. ~
  38. ~
  39. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement