0% found this document useful (0 votes)
18 views25 pages

1.os Practicle

Uploaded by

NARENDER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views25 pages

1.os Practicle

Uploaded by

NARENDER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

ADVANCED INSTITUTION OF TECHNOLOGY & MANAGEMENT

PRACTICLE FILE OF O.S.

SUBMITTED BY: SUBMITTED TO:


NAME: Aniket Narayan Mishra MRS. SUDHA MAM
CLASS: M.C.A. - 1ST SEM SIGN. :
ROLL NO. : MC21001
SUBJECT: OS LAB
SUBJECT CODE: MCA-20-117
INDEX
SR. NAME OF PROGRAMS REMARKS
NO.
1. MS-DOS Commands.
2. Unix Basic Commands.
3. W.A.P. using echo command in shell scripting.
4. W.A.P. using while loop in shell scripting.
5. W.A.P. using for loop in shell scripting.
6. W.A.P. using conditional statement.
7. W.A.P. using function in shell scripting.
8. W.A.P. to FCFS C.P.U. scheduling algorithm.
9. W.A.P. to SJF C.P.U. scheduling algorithm.
10. W.A.P. to Round Robin C.P.U. scheduling algorithm.
11. W.A.P. to SCAN disk scheduling algorithm.
12. W.A.P. to C-SCAN disk scheduling algorithm.
1. MS-DOS COMMANDS.
• CD/ (TO RETURN DRIVE LO8520CATION OUT OF ALL FOLDERS).
• CD.. (TO RETURN A STEP BACKWARD).
• CD (TO CHANGE DIRECTORY).
• DIR (TO OPEN LIST OF FILES & FOLDERS).
• MKDIR (TO CREATE FOLDER OR CREATE A NEW DIRECTORY).
• RMDIR (TO DELETE FOLDERS OR DELETE DIRECTORY).
• COPY CON (TO COPY A FILE THEN PRESS CTRL+Z).
• DEL (TO DELETE FILE).
2. UNIX BASIC COMMANDS.
COMMANDS ACTION
cat<file> Print contents of file in the command window.
cd<directory> Change directory.
cp<file><file2> Copy the contents of file into filled.
history List history of all commands issued at system prompt.
ls List of files and subdirectories in a directory.
ls -F List the difference b/w files and directories—directories
have a slash (/).
ls -l List the files with status/detail information.
ls -lt List the file information in long format, sorted by time
with newest files or newly changed files appearing first.
ls -a List all the files in a directory including dot files.
fs lq Lists AFS quota, space used, percentage used.
fs q Lists percentage of quota used.
mkdir<directory> Make a directory.
mv<file><file2> Move file to file2.
pwd Print the pathname of the current directory.
rm<file> Remove or delete files.
rmdir<directory> Remove directory.
Ctrl + C To negate a commands that you need have entered.
Some images of practical of Unix commands:
3. W.A.P. USING echo COMMAND IN A SHELL-SCRIPTING.
CODE:

RUN:
4. W.A.P. USING WHILE LOOP IN SHELL-SCRIPTING.
CODE:

RUN:
5. W.A.P.USING FOR LOOP IN SHELL-SCRIPTING.
CODE:

RUN:
6. W.A.P.USING CONDITIONAL STATEMENT.
CODE:

RUN:
7. W.A.P. USING FUNCTION IN SHELL-SCRIPTING.
CODE:

RUN:
8. W.A.P. TO FCFS C.P.U. SCHEDULING ALGORITHM.
#include<iostream>
using namespace std;
int main()

int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
cout<<"Enter total number of processes(maximum 20):";
cin>>n;

cout<<"\nEnter Process Burst Time\n";

for(i=0;i<n;i++)
{
cout<<"P["<<i+1<<"]:";
cin>>bt[i];

} wt[0]=0;
for(i=1;i<n;i++)

{
wt[i]=0;

for(j=0;j<i;j++)
wt[i]+=bt[j];
}
cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time";

for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];

cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
}
avwt/=i;
avtat/=i;
cout<<"\n\nAverage Waiting Time:"<<avwt;
cout<<"\nAverage Turnaround Time:"<<avtat;
return 0;

}
OUTPUT:
9. W.A.P. TO SJF C.P.U. SCHEDULING ALGORITHM.
#include<iostream>
using namespace std;
int main()

int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
cout<<"Enter number of process:";
cin>>n;

cout<<"\nEnter Burst Time:\n";


for(i=0;i<n;i++)
{
printf("p%d:",i+1);

scanf("%d",&bt[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{

pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])

pos=j;
}

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;

}
wt[0]=0;
for(i=1;i<n;i++)
{

wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}
avg_wt=(float)total/n;
total=0;
cout<<"\nProcess\t Burst Time \tWaiting Time\tTurnaround Time";

for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];

printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);


}
avg_tat=(float)total/n;
cout<<"\n\nAverage Waiting Time="<<avg_wt;

cout<<"\nAverage Turnaround Time=\n"<<avg_tat;


return 0;
}
OUTPUT:
10. W.A.P. TO ROUND ROBIN C.P.U. ALGORITHM.
#include <iostream>
#include <vector>
using namespace std;
int main()

{
int i,n,time,remain,temps=0,time_quantum;
int wt=0,tat=0;
cout<<"Enter the total number of process="<<endl;

cin>>n;
remain=n;
vector<int>at(n);
vector<int>bt(n);
vector<int>rt(n);

cout<<"Enter the Arrival time, Burst time for All the processes"<<endl;
for(i=0;i<n;i++)
{
cin>>at[i];
cin>>bt[i];
rt[i]=bt[i];

}
cout<<"Enter the value of time QUANTUM:"<<endl;

cin>>time_quantum;
cout<<"\n\nProcess\t:Turnaround Time:Waiting Time\n\n";
for(time=0,i=0;remain!=0;)
{

if(rt[i]<=time_quantum && rt[i]>0)


{
time += rt[i];
rt[i]=0;
temps=1;
}

else if(rt[i]>0)
{
rt[i] -= time_quantum;
time += time_quantum;

}
if(rt[i]==0 && temps==1)
{
remain--;
printf("Process{%d}\t:\t%d\t:\t%d\n",i+1,time-at[i],time-at[i]-bt[i]);
cout<<endl;

wt += time-at[i]-bt[i];
tat += time-at[i];
temps=0;

}
if(i == n-1)
i=0;

else if(at[i+1] <= time)


i++;
else

i=0;

cout<<"Average waiting time "<<wt*1.0/n<<endl;


cout<<"Average turn around time "<<tat*1.0/n<<endl;
return 0;
}
OUTPUT:
11. W.A.P. TO SCAN DISK SCHEDULING ALGORITHM.
#include<bits/stdc++.h>
using namespace std;
int main()
{

int i,j,k,n,m,sum=0,x,y,h;
cout<<"Enter the size of disk\n";
cin>>m;

cout<<"Enter number of requests\n";

cin>>n;
cout<<"Enter the requests\n";
vector <int> a(n),b;
for(i=0;i<n;i++){

cin>>a[i];
}
for(i=0;i<n;i++){
if(a[i]>m){
cout<<"Error, Unknown position "<<a[i]<<"\n";

return 0;
}
}
cout<<"Enter the head position\n";

cin>>h;
int temp=h;
a.push_back(h);
a.push_back(m);
a.push_back(0);
sort(a.begin(),a.end());
for(i=0;i<a.size();i++){
if(h==a[i])
break;
}

k=i;
if(k<n/2){
for(i=k;i<a.size();i++){
b.push_back(a[i]);

}
for(i=k-1;i>=0;i--){
b.push_back(a[i]);
}
}
else{
for(i=k;i>=0;i--){
b.push_back(a[i]);
}

for(i=k+1;i<a.size();i++){
b.push_back(a[i]);
}
}

temp=b[0];
cout<<temp;
for(i=1;i<b.size();i++){

cout<<" -> "<<b[i];

sum+=abs(b[i]-temp);
temp=b[i];
}
cout<<'\n';

cout<<"Total head movements = "<< sum<<'\n';


cout<<"Average head movement = "<<(float)sum/n<<'\n';
return 0;
}

OUTPUT:
12. W.A.P. TO C-SCAN DISK SCHEDULING ALGORITHM.
#include<bits/stdc++.h>
using namespace std;
int main()
{

int i,j,k,n,m,sum=0,x,y,h;
cout<<"Enter the size of disk\n";
cin>>m;

cout<<"Enter number of requests\n";

cin>>n;
cout<<"Enter the requests\n";
vector <int> a(n),b;
for(i=0;i<n;i++){

cin>>a[i];
}
for(i=0;i<n;i++){
if(a[i]>m){
cout<<"Error, Unknown position "<<a[i]<<"\n";

return 0;
}
}
cout<<"Enter the head position\n";

cin>>h;
int temp=h;
a.push_back(h);
a.push_back(m);
a.push_back(0);
sort(a.begin(),a.end());
for(i=0;i<a.size();i++){
if(h==a[i])
break;
}

k=i;
if(k<n/2){
for(i=k;i<a.size();i++){
b.push_back(a[i]);

}
for(i=0;i<=k-1;i++){
b.push_back(a[i]);
}
}
else{
for(i=k;i>=0;i--){
b.push_back(a[i]);
}

for(i=a.size()-1;i>=k+1;i--){
b.push_back(a[i]);
}
}

temp=b[0];
cout<<temp;
for(i=1;i<b.size();i++){

cout<<" -> "<<b[i];

sum+=abs(b[i]-temp);
temp=b[i];
}
cout<<'\n';

cout<<"Total head movements = "<< sum<<'\n';


cout<<"Average head movement = "<<(float)sum/n<<'\n';
return 0;
}

OUTPUT:

You might also like