OS Practical File (1900651)
OS Practical File (1900651)
1
Index
1. Windows Installation.
2. Ubuntu Installation.
3. Mac Installation.
10. Simulate the Bankers algorithm for deadlock avoidance and deadlock
prevention.
2
11. Implementing Shell Programming.
a ) To write a program to find whether a number is even or odd.
b) To write a program to find biggest in two numbers.
c) To Write a Program to Find Greatest InThree Numbers.
d) To find a factorial of a number using shell script.
e) To write a program to display the Fibonacci series.
f) write a program to print first 10 numbers using forloop
Step1. Insert the Windows 7 operating system disk into your DVD drive,
and then restart your computer
Step2.Youwillseeapromptthatsays‘Pressanykeytocontinue’aftertheZT
logodisappears.When you see this press any keyimmediately.
3
Step 3 ‘Starting Windows’ with the Windows7 logo will appear.
Step4.Languageoptions,bydefaultEnglishwillbesetalongwith“timeandcu
rrencyformat”and“keyboard or input method”
4
Step 6. End User License Agreement (E.U.L.A.), check the box to accept, and
click “Next”
Step7.“Whichtypeofinstallation?”windowwillappear.Upgradewillbegreyedo
ut;theonlyoptionyou should be able to choose is Custom(advanced).
Step8. “Where do you want to install windows?” Make sure the partition is
highlighted.
Step9.DeletethepartitionbyclickingonDriveoptions(advanced)onthebo
ttomrightcornerofthefield.
MakesurethepartitionishighlightedandclickonDelete.Ifdriveadvancedop
tionsisgreyedout,thenthe partition will not have to bedeleted.
*NOTE: Deleting the partitions will erase all data on the system
5
Step10.Disk0UnallocatedSpaceshouldbetheonlylistingatthispoint.Ifitispressn
ext,ifnotpleaseproceed to delete any additional partitions that may belisted.
Step11.The next
screenwillshow“InstallingWindows”.Thisprocessshouldtakeapproximately
10minutes after which the system willreboot.
*NOTE: Do not press any keys during this boot up process so as to not
disturb the rest of the installation.
Step12. The next screen will show “Installing Windows” again to complete
the installation process.
6
Step13.“SetupisstartingWindows”willappearonthescreen,thenyouwillbeask
edtocreateausernameand a computername.
Step 14. The next step will prompt you to create a password for your
account (optional)
Step15.Thenextscreenwillcomeupandaskyoutochooseoneofthreeoptions:“U
serecommendedsettings”, “Install important updates only” and “Ask
melater”.
7
Step16. This screen will allow you to choose your local time zone and also
adjust the date and time.
Step17.ClickontheappropriatelocationofyourcomputertoenableWindows7to
applythecorrectnetworksettings.
8
Practical No.: 2 Ubuntu Installation
DDownload Ubuntu
15.04 (64-bit)
DDownload Ubuntu
15.04(32-bit)
Once the iso file has been downloaded, burn it into DVD or USB drive
and make it bootable.
9
Make sure you have at least 6.6 GB free disk space and if you want to
download updates and third party tools at the installation, check both the
boxes and make sure system is connected to Internet
….
If your system has new hard drive and if nothing installed on it, then you
can choose the first option “Erase disk & Install Ubuntu”.
If you want LVM based file system, then use third option “Use LVM with
new Ubuntu Installation”
If you want to create customize partition table, the use last option
10
After the installation your PC will restart and your operating system is ready to
use.
Install of macOS on your Mac using the recovery utility. Make sure your Mac
is connected to a power source and has a steady connection to the internet
during the install process.
11
STEP:1
Turn on or reboot your Mac. You will access recovery utility this way.
Your computer needs access to the internet if you do not have a local copy of
macOS.
STEP:2
Press and hold ⌘Cmd+ R right away. This key combination tells your Mac to
reinstall the same version of macOS that was already
installed. If you're hoping for a different version, check out these alternatives:
To upgrade you macOS to the most current OS that is compatible with your
Mac, press Opt+⌘Cmd+ R. For example, a Mac from early 2012 will not be
compatible with macOS10.15, Catalina.
To install the macOS your Mac came with, no matter how out-dated,
12
STEP:3
STEP:4
Choose if you want to erase your disk. Be warned that this will erase
your disk and you will lose all information on your computer. You can
also opt to "Restore from Time Machine Backup" if you don't want to
lose everything.
STEP:5
Click to select Reinstall macOS. This will reinstall the macOS but will
keep your files and usersettings intact.
13
STEP:6
Click Continue. You will start the process of reinstalling macOS.
STEP:7
14
Follow the on-screen instructions to install MacOS. This includes
selecting where to install the OS.Please do not put your Mac to
sleep or close its lid during the installation process. You might see
your Mac restart a few times, show a blank screen, and show a few
progress bars, but that does not mean installation is done.
Practical No.: 4
15
Click Next to continue
You can choose multiple features or you can start with default
features.
Ignore the warning and Click on the “Yes” button to proceed for the
next step.
16
Click the install button. The next pop up window of UAC (Microsoft
User Account Control) will appear, click yes to proceed)
You will have to install drivers in Virtual Box to interact with the host
machine’s hardware as displayed in the figure. Click the install button
to continue.
17
After the installation completes, click the finish button.
Now the installation process of Virtual box has been completed. Start
Oracle VM Virtual Box after installation.
You have installed VirtualBox and you have downloaded the ISO for
Linux. You are now set to install Linux in VirtualBox.
18
Start VirtualBox, and click on the New symbol. Give the virtual OS a
relevant name.
Allocate RAM to the virtual OS. My system has 8GB of RAM and I
decided to allocate 2GB of it. You can use more RAM if your system
has enough extra.
Create a virtual disk. This serves as the hard disk of the virtual
Linux system. It is where the virtual system will store its files.
19
using the VDI file type here.
20
The recommended size is 10 GB. However, I suggest giving it more
space if possible. 15-20 GB is preferable
Once everything is in place, it’s time to boot that ISO and install
Linux as a virtual operating system.
21
Soon you’ll find yourself inside Linux. You should be presented with
the option to install it.
22
Select ‘Erase disk and install Ubuntu’. Don’t worry. It won’t delete
anything on your Windows operating system. You are using the
virtual disk space of 15-20GB that we created in previous steps. It
won’t impact the real operating system.
23
Things are pretty straightforward from here.
Self explanatory.
Try to choose a password that you can remember. You can also reset
the password in Ubuntu if you forget it.
You are almost done. It may take 10-15 minutes to complete the
installation.
24
Once the installation finishes, restart the virtual system.
If it gets stuck on the screen below, you may close the VirtualBox.
Practical No.: 5
25
Aim: Implementation of Linux Command.
File Commands
1. ls Directory listing
2. ls -al Formatted listing with hidden files
3. ls -lt Sorting the Formatted listing by time modification
4. cd dir Change directory to dir
5. cd Change to home directory
6. pwd Show current working directory
7. mkdir Creating a directory dir
dir
8. cat >file Places the standard input into the file
9. more Output the contents of the file
file
10. head file Output the first 10 lines of the file
11. tail file Output the last 10 lines of the file
12. tail -f file Output the contents of file as it grows,starting
with the last 10 lines
13. touch Create or update file
file
14. rm file Deleting the file
15. rm -r dir Deleting the directory
16. rm -f file Force to remove the file
17. rm -rf Force to remove the directory dir
dir
26
18. cp file1 Copy the contents of file1 to file2
file2
19. cp -r dir1 Copy dir1 to dir2;create dir2 if not present
dir2
20. mv file1 Rename or move file1 to file2,if file2 is an existing
file2 directory
21. ln -s file Create symbolic link link to file
link
Process management
27
• 4-read(r)
• 2-write(w)
• 1-execute(x)
Searching
1. grep pattern Search for pattern in file
2. grep -r pattern Search recursively for pattern in dir
dir
3. command | Search pattern in the output of a command
grep
pattern
4. locate file Find all instances of file
5. find . -name Searches in the current directory
filename (represented by a period) and below it, for
files and directories with names starting
with filename
6. pgrep pattern Searches for all the named processes ,
that matches with the pattern and, by
default, returns their ID
System Info
28
7. uname -a Show kernel information
8. cat Cpu information
/proc/cpuinfo
9. cat Memory information
proc/meminfo
10. man command Show the manual for command
11. df Show the disk usage
12. du Show directory space usage
13. free Show memory and swap usage
14. whereis app Show possible locations of app
15. which app Show which applications will be run by
default
Compression
29
8. gzip -d file.gz Decompresses file.gz back to file
Network
1. ping host Ping host and output results
2. whois domain Get whois information for domains
3. dig domain Get DNS information for domain
4. dig -x host Reverse lookup host
5. wget file Download file
6. wget -c file Continue a stopped download
Shortcuts
1. ctrl+c Halts the current command
2. ctrl+z Stops the current command, resume with
fg in the foreground or bg in the
background
3. ctrl+d Logout the current session, similar to exit
4. ctrl+w Erases one word in the current line
5. ctrl+u Erases the whole line
6. ctrl+r Type to bring up a recent command
7. !! Repeats the last command
8. exit Logout the current session
30
Practical No.: 6
#include<iostream>
using namespace std;
int main()
{
int n,bt[20],wt[20],tat[20],avwt = 0, avtat = 0;
cout<<"Enter Total Number of Processor: ";
cin>>n;
cout<<endl<<"Enter Process Burst Time"<<endl;
for(int i=0;i<n;i++)
{
cout<<"Process["<<i+1<<"]: ";
cin>>bt[i];
}
wt[0]=0;
for(int i=1;i<n;i++)
{
wt[i]=0;
31
for(int j=0;j<i;j++)
wt[i]+= bt[j];
}
cout<<endl<<"Process\t Burst Time\t Watimg Time\t
Turnarround Time";
for(int i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+= wt[i];
avtat+= tat[i];
cout<<endl<<"Process["<<i+1<<"]"<<"\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\
t"<<tat[i];
}
cout<<endl<<endl<<"Average Wating Time: "<<avwt;
cout<<endl<<"Average Turnaround Time: "<<avtat;
return 0;
}
Output:-
32
Practical No.: 7
#include<iostream>
using namespace std;
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float awt, atat;
cout<<"Enter number of process: ";
cin>>n;
cout<<endl<<"Enter Burst Time:"<<endl;
for(i=0;i<n;i++)
{
cout<<"p"<<i+1<<": ";
cin>>bt[i];
p[i]=i+1;
}
for(i=1;i<n;i++)
{
33
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=0;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
awt=(float)total/n;
total=0;
34
cout<<endl<<"Process\t Burst Time \t Waiting Time\tTurn
Around Time";
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
cout<<endl<<"p"<<p[i]<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
}
atat=(float)total/n;
cout<<endl<<endl<<"Averge Waiting time= "<<awt;
cout<<endl<<"Average Turnaround Time= "<<atat;
return 0;
}
Output:-
35
Practical No.: 8
#include<iostream>
using namespace std;
struct process
{
int no;
int at,et,wt,tt;
int tet,t;
};
int main()
{
process p[99];
int i,j,k;
cout<<"Enter No. of Processes: ";
36
int np;
cin>>np;
for(i=0;i<np;i++)
{
cout<<endl<<"Enter Execution Time of Process "<<i+1<<":
";
cin>>p[i].et;
p[i].tet=p[i].et;
p[i].at=p[i].t=p[i].tt=p[i].wt=0;
p[i].no=i+1;
}
cout<<endl<<"Enter Time Quantum: ";
int q;
cin>>q;
cout<<endl<<"Enter Data: ";
cout<<endl<<"Process Execution Time";
for(i=0;i<np;i++)
{
cout<<endl<<p[i].no<<"\t"<<p[i].et;
}
int totaltime = 0;
for(i=0;i<np;i++){
totaltime+=p[i].et;
}
37
i=0;
k=0;
int rrg[99];
for(j=0;j<totaltime;j++)
{
if((k==0)&&(p[i].et!=0))
{
p[i].wt=j;
if((p[i].t!=0))
{
p[i].wt=q*p[i].t;
}
}
if((p[i].et!=0)&&(k!=q))
{
rrg[j]=p[i].no;
p[i].et+1;
k++;
}
else
{
if((k==q)&&(p[i].et!=0))
{
p[i].t+=1;
38
}
i=i+1;
if(i==np)
{
i=0;
}
k=0;
j=j+1;
}
}
int twt=0;
int ttt=0;
cout<<endl<<"\t\tResult of Round Robin"<<endl;
cout<<endl<<"Processes\tExecution Time\tWating Time\Turn
Around Time";
for(i=0;i<np;i++)
{
p[i].tt=p[i].wt+p[i].tet;
ttt+=p[i].tt;
twt+=p[i].wt;
cout<<endl<<p[i].no<<"\t\t\t"<<p[i].tet<<"\t"<<p[i].wt<<"\t\t"<<p[i].
tt;
}
cout<<endl<<"Average Waiting Time"<<(float)twt/np;
cout<<endl<<"Average Turn Around time: "<<(float)ttt/np;
39
return 0;
}
Output:-
Practical No.: 9
#include<iostream>
using namespace std;
int main()
{
int bt[20], p[20], wt[20], tat[20], pr[20], i, j, n, total=0, pos,
temp, avgwt, avgtat;
cout<<"Enter Total Number Of Process: ";
cin>>n;
40
cout<<endl<<"Enter Burst Time and Priority:"<<endl;
for(i=0;i<n;i++)
{
cout<<endl<<"P["<<i+1<<"]\n";
cout<<"Burst Time: ";
cin>>bt[i];
cout<<"Priority: ";
cin>>pr[i];
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=pr[i];
bt[i]=bt[pos];
bt[pos]=temp;
41
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<n;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avgwt=total/n;
total=0;
cout<<endl<<"Process\t Burst Time \tWaiting Time\tTurn
Around Time";
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calaulate turn around time
total+=tat[i];
cout<<endl<<"P["<<p[i]<<"]\t "<<bt[i]<<"\t\t
"<<wt[i]<<"\t\t "<<tat[i];
}
42
avgtat=total/n; //average turn around time
cout<<endl<<endl<<"Average Wating Time= "<<avgwt;
cout<<endl<<"Average Turn Around Time= "<<avgtat;
return (0);
}
Output:-
Practical No.: 10
#include<iostream>
43
using namespace std;
#define MAX 20
class bankers
{
private:
int al[MAX][MAX],m[MAX][MAX],n[MAX][MAX],avail[MAX];
int nop,nor,k,result[MAX],pnum,work[MAX],finish[MAX];
public:
bankers();
void input();
void method();
int search(int);
void display();
};
bankers::bankers()
{
k=0;
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
al[i][j]=0;
m[i][j]=0;
44
n[i][j]=0;
}
avail[i]=0;
result[i]=0;
finish[i]=0;
}
}
void bankers::input()
{
int i,j;
cout<<"Enter the number of processes:";
cin>>nop;
cout<<"Enter the number of resources:";
cin>>nor;
cout<<"Enter the allocated resources for each process: "<<endl;
for(i=0;i<nop;i++)
{
cout<<"\nProcess "<<i;
for(j=0;j<nor;j++)
{
cout<<"\nResource "<<j<<":";
cin>>al[i][j];
}
}
45
cout<<"Enter the maximum resources that are needed for each
process: "<<endl;
for(i=0;i<nop;i++)
{
cout<<"\nProcess "<<i;
for(j=0;j<nor;j++)
{
cout<<"\nResouce "<<j<<":";
cin>>m[i][j];
n[i][j]=m[i][j]-al[i][j];
}
}
cout<<"Enter the currently available resources in the system: ";
for(j=0;j<nor;j++)
{
cout<<"Resource "<<j<<":";
cin>>avail[j];
work[j]=-1;
}
for(i=0;i<nop;i++)
finish[i]=0;
}
void bankers::method()
{
46
int i=0,j,flag;
while(1)
{
if(finish[i]==0)
{
pnum =search(i);
if(pnum!=-1)
{
result[k++]=i;
finish[i]=1;
for(j=0;j<nor;j++)
{
avail[j]=avail[j]+al[i][j];
}
}
}
i++;
if(i==nop)
{
flag=0;
for(j=0;j<nor;j++)
if(avail[j]!=work[j])
flag=1;
for(j=0;j<nor;j++)
work[j]=avail[j];
47
if(flag==0)
break;
else
i=0;
}
}
}
int bankers::search(int i)
{
int j;
for(j=0;j<nor;j++)
if(n[i][j]>avail[j])
return -1;
return 0;
}
void bankers::display()
{
int i,j;
cout<<endl<<"OUTPUT:";
cout<<endl<<"========";
cout<<endl<<"PROCESS\t ALLOTED\t MAXIMUM\t
NEED";
for(i=0;i<nop;i++)
48
{
cout<<"\nP"<<i+1<<"\t ";
for(j=0;j<nor;j++)
{
cout<<al[i][j]<<" ";
}
cout<<"\t ";
for (j=0;j<nor;j++)
{
cout<<m[i][j]<<" ";
}
cout<<"\t";
for(j=0;j<nor;j++ )
{
cout<<n[i][j]<<" ";
}
}
cout<<"\nThe sequence of the safe processes are: \n";
for(i=0;i<k;i++)
{
int temp = result[i]+1 ;
cout<<"P"<<temp<<" ";
}
cout<<"\nThe sequence of unsafe processes are: \n";
int flg=0;
49
for (i=0;i<nop;i++)
{
if(finish[i]==0)
{
flg=1;
}
cout<<"P"<<i<<" ";
}
cout<<endl<<"RESULT:";
cout<<endl<<"=======";
if(flg==1)
cout<<endl<<"The system is not in safe state and deadlock may
occur!!";
else
cout<<endl<<"The system is in safe state and deadlock will not
occur!!";
}
int main()
{
cout<<" DEADLOCK BANKER’S ALGORITHM "<<endl;
bankers B;
B.input ( );
B.method ( );
B.display ( );
return 0;
50
}
Output:-
51
Practical No.: 11
ALGORITHM:
STEP 1: Read the input number.
STEP 2: Perform modular division on input number by 2.
STEP 3: If remainder is 0 print the number is even.
STEP 4: Else print number is odd.
STEP 5: Stop the program.
PROGRAM :
echo "enter the number"
readnum
echo "enter the number"
readnum
if [ `expr $num % 2` -eq 0 ]
then
echo "number is even"
else
52
echo "number is odd"
OUTPUT:
enter the number: 5
the number is odd.
RESULT:
Thus the program has been executed successfully.
PROGRAM:
echo "enter the number"
read a b
if [ $a -gt $b ]
then
echo "A is greater"
else
echo "B is greater"
OUTPUT:
53
Enter The Two Number:
23 67
B is Greater.
RESULT:
Thus the program has been executed successfully.
c) AIM: To Write a Program to Find Greatest In Three Numbers.
ALGORITHM:
STEP 1: Read The Three Numbers.
STEP 2: If A Is Greater Than B And A Is Greater Than C Then Print A Is
Big.
STEP 3: Else If B is greater Than C Then C Is Big.
STEP 4: Else Print C Is Big.
STEP 5: Stop The Program.
PROGRAM:
echo "enter three numbers"
read a b c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "A is Greatest"
else if [ $b -gt $c ]
then
echo "B is Greatest"
else
echo "C is Greatest"
54
fi
fi
OUTPUT:
ENTER THREE NUMBERS:
23 54 78
C is Greatest.
RESULT:
Thus the program has been executed successfully.
ALGORITHM:
Step 1: read a number.
Step 2: Initialize fact as 1.
Step 3: Initialize I as 1.
Step 4: While I is lesser than or equal to no.
Step 5: Multiply the value of I and fact and assign to fact increment
the value of I by 1.
Step 6: print the result.
Step 7: Stop the program
PROGRAM:
55
echo "enter the number"
read n
fact=1
i=1
while [ $i -le $n ]
do
fact=`expr $i \* $fact`
i=`expr $i + 1`
done
echo "the fcatorial number of $ni is $fact
OUTPUT:
Enter the number :
4
The factorial of 4 is 24.
ALGORITHM:
Step 1: Initialize n1& n2 as 0 & 1.
Step 2: enter the limit for Fibonacci.
Step 3: initialize variable as 0
Step 4: Print the Fibonacci series n1 and n2.
Step 5: While the var number is lesser than lim-2
Step 6: Calculate n3=n1+n2.
56
Step 7: Set n1=n2 and n2=n3
Step 8: Increment var by 1 and print n2
Step 9: stop the program.
PROGRAM:
echo " ENTER THE LIMIT FOR FIBONNACI SERIES"
readlim
n1=0
n2=1
var=0
echo "FIBONACCI SERIES IS "
echo "$n1"
echo "$n2"
while [ $var -lt `expr $lim - 2` ]
do
n3=`expr $n1 + $n2 `
n1=`expr $n2 `
n2=`expr $n3 `
var=`expr $var + 1 `
echo "$n2"
done
OUTPUT :
enter the limit for Fibonacci:
5
The Fibonacci series is:
57
0
1
1
2
3
RESULT:
Thus the program has been executed successfully.
f) AIM :To write a program to print first 10 numbers using for loop.
ALGORITHM:
Step 1: Initialize value of a variable.
Step 2: Set the limit.
Step 3: Increment the value of variable.
Step 4: Print the result.
PROGRAM :
echo “Display first 10 numbers”
for((i=1;i<=10;i++))
do
echo $i
done
58
OUTPUT:
Display first 10 numbers
1
2
3
4
5
6
7
8
9
10
RESULT:
The program has been executed successfully
59