You are on page 1of 3

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

SOFTWARE ENGINEERING DEPARTMENT (SED)

Lab #08

SUBMITTED TO:

Ma’am Rabia Arshad

SUBMITTED BY:

Muhammad Yasir Hassan

ROLL NUMBER:

19-SE-31

SECTION:

Alpha (α)

DATE:

01-12-2021
Lab Task
Task 1:
Write a program where a child process is created to implement Fibonacci series.
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>
int main()
{
pid_t pid,status;
pid = fork();
if (pid==0)
{
int num,a=-1,b=1,c;
printf("\n Enter the Number: ");
scanf("%d",&num);
printf("\n Your Series is: ");
for(int i=0;i<num;i++)
{
c = a + b;
a = b;
b = c;
printf("%d ",c);
}
printf("\n");
exit(0);
}
else
wait(&status);
return 0;
}
Task 2:
Write a program where a child process is created to execute a command which accepts
a pathname as argument and creates the components in that pathname and parent
process executes a command and checks that the required components are successfully
made by child process.
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>
int main()
{
char fileName[40];
printf("\n Enter the Filename: ");
scanf("%s",fileName);
pid_t pid,status;
pid = fork();
if (pid==0)
{
execl("/bin/touch","touch",fileName,NULL);
}
else if (pid==-1)
{
perror("\n Error in Fork");
exit(1);
}
else
{
wait(&status);
execl("/bin/realpath","realpath",fileName,NULL); // find alternative realpath
}
return 0;
}

You might also like