Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <stdlib.h>
- int main (void){
- pid_t pid;
- pid_t mychild;
- pid_t parentid;
- int first=0,second=1;
- int third,num;
- printf("Enter The number for Fibonacci sequence:-");
- scanf("%d",&num);
- pid=fork();
- if (pid == 0){
- printf("\n The parent process id is: %d\n ",getppid());
- do{
- printf("%d,",first);
- third=first+second;
- first=second;
- second=third;
- }while(first <= num);
- printf("\n");
- }
- else if (pid > 0){
- mychild=wait (NULL);
- printf ("\nChild Process ID is : %d",mychild);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement