Académique Documents
Professionnel Documents
Culture Documents
141030008
OPERATING SYSTEMS
LAB
(CSX-325)
Submitted To:
Submitted By:
Ishan Bansal
14103008
Dept. of CSE
141030008
INDEX
Sr. No.
Title
Page No.
1.)
1-6
2.)
7-10
3.)
11-11
4.)
5.)
6.)
7.)
12-12
13-13
14-15
16-17
18-19
20-21
22-25
26-29
31-34
Remarks
141030008
141030008
Windows is already installed here, well prepare a new partition for Linux Mint.
In the Installation Type window, choose Something Else:
Now, I have 3 NTFS and some ext4 partitions. If we dont have ext4 partition,
dont worry, we dont need that. As we can see in the picture below, one of the
NTFS partition consists of Windows installation. This should be untouched if we
want to keep your Windows installation safe.
I hope we have more than one NTFS (or FAT 32) partitions (i.e. Drives in
Windows term) on our hard disk, with one of them consisting of Windows
installation (usually C drive). What we need to do here is to delete a NTFS or
existing ext4 partition and create some free space. This will delete all the data
in that partition and this is why I asked we to verify if you have Windows
installed in a different partition.Click on the desired partition and press the to
delete the partition
141030008
Here,
choose
the size of root
(10
GB
is
enough but I
chose to have 20 here), choose ext4 file system, and mount point as / (i.e.
root):
141030008
The next step is to create Home. Try to allocate the maximum size to Home
because this is where well be downloading and keeping the files.
Once we have created Root, Swap and Home partitions, click on Install Now
button.
141030008
141030008
Once the installation is over, we will be presented with the option to keep
trying live version or to restart the system.
141030008
141030008
10
141030008
11
141030008
#include<stdio.h>
#include<unistd.h>
int main()
{
int k=fork();
if(k==0)
{
printf("Child process with pid = %d and ppid =
%d\n",getpid(),getppid());
}
else
{
printf("Parent process with pid = %d and child id =
%d\n",getpid(),k);
}
}
12
141030008
#include<stdio.h>
#include<unistd.h>
int main()
{
int n,i;
int k;
printf("Enter the number of processes to be started\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
k= fork();
if(k==0)
{
execle("/home/Ishan/Desktop/os/fj","f.c",(char *)NULL,(char *)NULL);
execlp("/home/Ishan/Desktop/os/fj","f.c",(char *)NULL);
}
}
}
Program print.c:// to print 100 numbers using 10 processes
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
int k=atoi(argv[0]);
int j=atoi(argv[1]);
int i=0;
for(i=k+1;i<=j;i++)
printf("%d ",i);
printf("\n");
}
13
141030008
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
signal
int k=fork();
if(k==0)
{
printf("Child id= %d parent id= %d\n",getpid(),getppid());
sleep(15);
printf("Parent Dead\n");
printf("Parent is dead. New parent id=%d\n",getppid());
}
else
{
printf("Parent process going to sleep\n");
sleep(5);
printf("Parent about to die with id:%d with child id
%d\n",getpid(),k);
}
}
14
141030008
Tag
WIFEXITED( status)
WEXITSTATUS( status)
WIFSIGNALED( status)
WTERMSIG( status)
WCOREDUMP( status)
Description
returns true if the child terminated normally, that is,
by calling exit(3) or _exit(2), or by returning from
main().
returns the exit status of the child. This consists of
the least significant 16-8 bits of the status
argument that the child specified in a call to exit()
or _exit() or as the argument for a return statement
in main(). This macro should only be employed
ifWIFEXITED returned true.
returns true if the child process was terminated by a
signal.
returns the number of the signal that caused the
child process to terminate. This macro should only
be employed if WIFSIGNALED returned true.
returns true if the child produced a core dump. This
15
WIFSTOPPED( status)
WSTOPSIG( status)
WIFCONTINUED( status)
Tag
WNOHANG
WUNTRACED
WCONTINUED
141030008
16
141030008
#include<stdio.h>
struct pair
{
double a,b;
};
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
struct pair ar[n];
double waiting[n];
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&ar[i].a,&ar[i].b);
}
waiting[0]=0;
double current=ar[0].b;
for(int i=1;i<n;i++)
{
if(ar[i].a<current)
waiting[i]=current-ar[i].a;
else
waiting[i]=0;
current=current+ar[i].b;
}
double totalwaiting=0;
for(int i=0;i<n;i++)
{
totalwaiting+=waiting[i];
}
double avg=totalwaiting/n;
printf(" Pid | Turn Around time | Waited Turn Around Time
\n");
for(int i=0;i<55;i++)
printf("-");
printf("\n");
double avg1=0;
double avg2=0;
17
141030008
for(int i=0;i<n;i++)
{
avg1+=waiting[i]+ar[i].b;
avg2+=(waiting[i]+ar[i].b)/ar[i].b;
printf(" P%d | %lf\t
|
%lf\n",i+1,waiting[i]
+ar[i].b,(waiting[i]+ar[i].b)/ar[i].b);
}
for(int i=0;i<55;i++)
printf("-");
printf("\n");
printf(" Average| %lf\t
|
%lf\n",avg1/n,avg2/n);
}
18
141030008
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int glo=0;
int n;
scanf("%d",&n);
double counter=0.0;
pair<int,double> completed[n+1];
pair<pair<double,double> ,int > se[n+1];
pair<pair<double,double> ,int > oe[n+1];
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&se[i].first.second,&se[i].first.first);
se[i].second=i;
oe[i].first.second=se[i].first.second;
oe[i].first.first=se[i].first.first;
}
double timer=0.0;
int front=0;
int ind;
for(int k=0;k<n;k++)
{
ind=n;
for(int i=front;i<n;i++)
{
if(se[i].first.second>timer)
{
ind=i;
break;
}
}
sort(se+front,se+ind);
timer+=se[front].first.first;
completed[glo].first=se[front].second;
completed[glo].second=timer;
front++;
glo++;
}
printf(" Pid | Turn Around time | Waited Turn Around Time \n");
19
141030008
for(int i=0;i<55;i++)
printf("-");
printf("\n");
double avg1=0;
double avg2=0;
for(int i=0;i<n;i++)
{
int k=completed[i].first;
avg1+=(completed[i].second-oe[k].first.second);
double tr=(completed[i].second-oe[k].first.second);
double service=((completed[i].secondoe[k].first.second)/oe[k].first.first);
avg2+=service;
printf(" P%d | %lf\t
|
%lf\n",k+1,tr,service);
}
for(int i=0;i<55;i++)
printf("-");
printf("\n");
printf(" Average| %lf\t
|
%lf\n",avg1/n,avg2/n);
}
20
141030008
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
int n;
cin>>n;
pair<double,double> ar[n];
pair<int,pair<double,double> > br[n];
int has[n]={0};
int glo=0;
for(int i=0;i<n;i++)
{
cin>>ar[i].first>>ar[i].second;
}
double timer=0;
while(1)
{
double max=-10,k;
int ind=-1;
for(int i=0;i<n;i++)
{
if((has[i]==0)&&(ar[i].first<=timer))
{
k=(timer-ar[i].first)+ar[i].second;
k=k/ar[i].second;
if(k>max)
{
max=k;
ind=i;
}
}
}
if(ind==-1)
break;
else
{
has[ind]=1;
timer=timer+ar[ind].second;
br[glo].first=ind;
double temp=timer-ar[ind].first;
21
br[glo].second.first=temp;
br[glo++].second.second=temp/ar[ind].second;
141030008
printf(" Pid | Turn Around time | Waited Turn Around Time \n");
for(int i=0;i<55;i++)
printf("-");
printf("\n");
double avg1=0;
double avg2=0;
for(int i=0;i<n;i++)
{
avg1+=br[i].second.first;
avg2+=br[i].second.second;
printf(" P%d | %lf\t
|
%lf\n",br[i].first+1,br[i].second.first,br[i].second.second);
}
for(int i=0;i<55;i++)
printf("-");
printf("\n");
printf(" Average| %lf\t
|
%lf\n",avg1/n,avg2/n);
}
22
141030008
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false)
int main()
{
freopen("input.txt","r",stdin);
//freopen("output1.txt","w",stdout);
fast_io;
int n;
queue<int> q;
cin>>n;
double timer=0.0;
double time[n];
int has[n]={0};
pair<double,double> ar[n+1];
for(int i=1;i<=n;i++)
{
cin>>ar[i].first>>ar[i].second;
time[i]=ar[i].second;
}
double completed[n+1]={0.0};
double timeslice=1.0;
int mkg=0;
int pointer=2;
printf("Gantt Chart for the algorithm is \n");
23
141030008
q.push(1);
while(1)
{
printf("%d-%d--->P%d \n",mkg,mkg+1,q.front());
int kl=q.front();
time[q.front()]--;
q.pop();
timer+=timeslice;
while(1)
{
if(pointer==n+1)
break;
if(ar[pointer].first<=timer)
{
q.push(pointer);
pointer++;
}
else
break;
}
if(time[kl]!=0)
{
q.push(kl);
}
else
{
completed[kl]=timer;
24
141030008
if(q.size()==0)
break;
mkg++;
}
cout<<endl;
double tat[n+1],wtat[n+1];
double avg1=0;
double avg2=0;
for(int i=1;i<=n;i++)
{
tat[i]=completed[i]-ar[i].first;
avg1+=tat[i];
wtat[i]=tat[i]/ar[i].second;
avg2+=wtat[i];
}
printf(" Pid | Turn Around time | Waited Turn Around Time
\n");
for(int i=0;i<55;i++)
printf("-");
printf("\n");
for(int i=1;i<=n;i++)
{
printf(" P%d |
%lf\t
}
for(int i=0;i<55;i++)
25
%lf\n",i,tat[i],wtat[i]);
141030008
printf("-");
printf("\n");
printf(" Average|
%lf\t
%lf\n",avg1/n,avg2/n);
26
141030008
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false)
int main()
{
freopen("input.txt","r",stdin);
//freopen("output1.txt","w",stdout);
fast_io;
int n;
cin>>n;
double timer=0.0;
int mkg=0;
int time[n];
pair<double,double> ar[n+1];
for(int i=1;i<=n;i++)
{
cin>>ar[i].first>>ar[i].second;
time[i]=0;
}
double completed[n+1]={0.0};
int has[n+1]={0};
int ind,min;
while(1)
{
ind=-1,min=INT_MAX;
27
141030008
for(int i=1;i<=n;i++)
{
if(has[i]==0&&ar[i].first<=timer)
{
if(time[i]<min)
{
min=time[i];
ind = i;
}
}
}
if(ind==-1)
break;
printf("%d-%d--->P%d\n",mkg,mkg+1,ind);
time[ind]++;
if(time[ind]==ar[ind].second)
{
completed[ind]=timer+1.0;
has[ind]=1;
}
timer+=1.0;
mkg++;
}
cout<<endl;
double tat[n+1],wtat[n+1];
double avg1=0;
28
141030008
double avg2=0;
for(int i=1;i<=n;i++)
{
tat[i]=completed[i]-ar[i].first;
avg1+=tat[i];
wtat[i]=tat[i]/ar[i].second;
avg2+=wtat[i];
}
printf(" Pid | Turn Around time | Waited Turn Around Time
\n");
for(int i=0;i<55;i++)
printf("-");
printf("\n");
for(int i=1;i<=n;i++)
{
printf(" P%d |
%lf\t
%lf\n",i,tat[i],wtat[i]);
}
for(int i=0;i<55;i++)
printf("-");
printf("\n");
printf(" Average|
%lf\t
%lf\n",avg1/n,avg2/n);
29
141030008
30
141030008
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false)
int main()
{
freopen("input.txt","r",stdin);
//freopen("output1.txt","w",stdout);
fast_io;
int n;
cin>>n;
double timer=0.0;
int mkg=0;
int time[n];
pair<double,double> ar[n+1];
for(int i=1;i<=n;i++)
{
cin>>ar[i].first>>ar[i].second;
time[i]=ar[i].second;
}
double completed[n+1]={0.0};
int has[n+1]={0};
int ind,min;
while(1)
{
ind=-1,min=INT_MAX;
31
141030008
for(int i=n;i>=1;i--)
{
if(has[i]==0&&ar[i].first<=timer)
{
if(time[i]<min)
{
min=time[i];
ind = i;
}
}
}
if(ind==-1)
break;
printf("%d-%d--->P%d\n",mkg,mkg+1,ind);
time[ind]--;
if(time[ind]==0)
{
completed[ind]=timer+1.0;
has[ind]=1;
}
timer+=1.0;
mkg++;
}
cout<<endl;
double tat[n+1],wtat[n+1];
double avg1=0;
32
141030008
double avg2=0;
for(int i=1;i<=n;i++)
{
tat[i]=completed[i]-ar[i].first;
avg1+=tat[i];
wtat[i]=tat[i]/ar[i].second;
avg2+=wtat[i];
}
printf(" Pid | Turn Around time | Waited Turn Around Time
\n");
for(int i=0;i<55;i++)
printf("-");
printf("\n");
for(int i=1;i<=n;i++)
{
printf(" P%d |
%lf\t
%lf\n",i,tat[i],wtat[i]);
}
for(int i=0;i<55;i++)
printf("-");
printf("\n");
printf(" Average|
%lf\t
%lf\n",avg1/n,avg2/n);
33
141030008
34