You are on page 1of 6

NAME : MANSI ARORA

ROLL NO. : 20570046

UNVERSITY ROLL NO. :


20033570031

SUBJECT : OPERATING
SYSTEM

COURSE : B.SC. (HONS.)


COMPUTER SCIENCE
PARENT AND CHILD
EXECUTING
DIFFERENTCODE IN
SAME PROGRAM :

CODE :

#include <iostream>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
using namespace std;

int main() {
int x;
int a=0;
x=fork();
if(x<0){
cout<<"Fork has Failed!!";
exit(0);
}
else{
if(x==0){
int n ,limit, t1 = 0, t2 = 1, next = 0;
cout<<"child process****\n";
cout <<"Enter the limit of Fibonacci series";
cin>>n;

cout << "\n First "<<n<<"terms of Fibonacci series are :-


"<<endl;

for(int a=0;a<n;a++)
{
if (a <= 1)
next = a;
else
{
next = t1 + t2;
t1 = t2;
t2 = next;
}
cout << next << ", ";
}
}
else{
wait(NULL);
int num ,factorial=1;
cout<<"\nparent process***\n";
cout<<" \n Number To Find Its Factorial: ";
cin>>num;

for (int a=1;a<=num;a++) {


factorial=factorial*a;
}

cout<<"\n Factorial of Given Number is


="<<factorial<<endl;
}
}
// your code goes here
return 0;
}
OUTPUT :

You might also like