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 childid;
- pid_t parentid;
- int fab1=0,fab2=1,fab3,i,num;
- printf("Enter a number");
- scanf("%d",&num);
- pid=fork();
- if (pid == 0){
- childid=getpid();
- parentid=getppid();
- printf("\n The parent process id is: %d\n, ",parentid);
- printf("%d,%d,",fab1,fab2);
- for(i=2;i<=num;++i){
- fab3=fab1+fab2;
- printf("%d,",fab3);
- fab1=fab2;
- fab2=fab3;
- }
- printf("\n");
- exit(0);
- }
- else if (pid > 0){
- int x;
- 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
- // 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
- printf ("Child Process ID is : %d",x);
- }
- return 0;
- }
- ~
- ~
- ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement