Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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. }
  27. printf("\n");
  28. exit(0);
  29. }
  30. else if (pid > 0){
  31. sleep(100);// meken wene parent process eka sleep krna eka , when the child's executionis done parent is sleeping eka nisa process table ekn child ain wenne na
  32. int x;
  33. // x=wait (NULL);// wait use krne process table ekn ain krnda process ekata, sleeeping nisa ain wenne process table eken
  34. printf ("Child Process ID is : %d",x);
  35. }
  36. return 0;
  37. }
  38. ~
  39. ~
  40. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement