Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 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 mychild;
  9. pid_t parentid;
  10. int first=0,second=1;
  11. int third,num;
  12. printf("Enter The number for Fibonacci sequence:-");
  13. scanf("%d",&num);
  14. pid=fork();
  15. if (pid == 0){
  16. printf("\n The parent process id is: %d\n ",getppid());
  17. do{
  18. printf("%d,",first);
  19. third=first+second;
  20. first=second;
  21. second=third;
  22. }while(first <= num);
  23. printf("\n");
  24. }
  25. else if (pid > 0){
  26. mychild=wait (NULL);
  27. printf ("\nChild Process ID is : %d",mychild);
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement