OS Complete File
OS Complete File
SUBMITTED TO :
SUBMITTED BY :
Mr. Nitesh Singh Bhati
Ashish kumar (20318002718)
{ Asst. Professor,
rd
(B.Tech - CSE) 3 Year Dept. of Comp. Sc. Engg.}
Section-A
Operating System GGSIPU ETCS-304
INDEX
EXPERIMENT 1
INSTALLATION OF UBUNTU
1. Ubuntu will always be free of charge, and there is no extra fee for the
“enterprise edition”, we make our very best work available to everyone
on the same Free terms.
2. Ubuntu includes the very best in translations and accessibility
infrastructure that the Free Software community has to offer, to make
Ubuntu usable by as many people as possible.
3. Ubuntu is shipped in stable and regular release cycles; a new release
will be shipped every six months. Every two even years an Ubuntu long
term support (LTS) release will become available, that is supported for
5 years. The Ubuntu releases in between (known as development or
non-LTS releases) are supported for 9 month each.
4. Ubuntu is entirely committed to the principles of open source software
development; we encourage people to use open source software,
improve it and pass it on.
5. Ubuntu is suitable for both desktop and server use. The current Ubuntu
release supports Intel x86 (IBM-compatible PC), AMD64 (x86-64),
ARMv7,
Sponsorship by Canonical
Ubuntu 14.04 LTS has been released officially & code name is Trusty
Tahr. Ubuntu is the fastest growing desktop operating system
consists of Ubuntu
14.04 LTS 32-bit
and Ubuntu 14.04 LTS 64-bit.
• Libreoffice-4.2.3
• AppArmor with lot of new feature
• Xorg-15.01 (Display Server)
• Ubuntu Desktop – y with lot of new features
Unit
• Upstart 1.12.1
• Oxide – Oxide is a webview based on Chromium to deliver web
content. Oxide allows us to better support 3rd party developers and
applications within the Ubuntu archive by providing a fast and secure
Step 3: Prepare to Install Ubuntu, make sure your system has enough
free space (atleast 6.4 GB), connected to Internet & power source
Click on Continue…
Step 4: Installation Type: You can select default option, in which data
on disk will be erased, if you want you’re customize partition table, then
select ‘Something else’ option. If you want encrypt the drive, then select
‘Encrypt the new Ubuntu installation for security‘.
In my case i am creating customize partition table by selecting
‘something else’
Click on Continue….
Step 8: Set the HostName and User Name with the password.
Click on Continue….
Step 10: After the installation is completed, it will ask you to reboot the
Machine.
Step 11: Login prompt after installation – Use same credentials that
you have set during installation
Step 12: Screen after the Entering the Credentials
EXPERIMENT2
BASIC LINUX COMMANDS
1) Command : cat
a) To Create a New File:
Synatax : cat > filename
[lab1@lab1-Lenovo-product:~]$ cat>
one.txt Hi
Welcome to IT Lab
Engineering &
Technology Delhi
Pressing Ctrl+z to save the file [2]+ Stopped cat
>one.txt [lab1@lab1-Lenovo-product:~]$
b) To Display the Contents of the File :
Syntax : cat filename
[lab1@lab1-Lenovo-product:~]$ cat
one.txt Hi
Welcome to IT Lab
Engineering &
Technology Delhi
[lab1@lab1-Lenovo-product:~]$
2) Command : mkdir
Syntax :mkdir filename
[lab1@lab1-Lenovo-product:~]$ mkdir
programs [lab1@lab1-Lenovo-product:~]$ ls
a.outcollege.txt fir.sh new.txt
second.sh col1.txt coll.txt firs.sh
one pgms college2.txt file.txt
one.txt programs`
[lab1@lab1-Lenovo-product:~]$
/home/it
[lab1@lab1-Lenovo-product:~]$
c) [lab1@lab1-Lenovo-product:~]$ ls -a
. .bashrc .emacs.d new.txt .swn .xemacs
.. col1.txt file.txt one .swo
.zshrc a.outcollege2.txt fir.sh
one.txt .swp
.bash_history college.txt firs.sh pgms .viminfo
.bash_logout coll.txt .five.sh.swp programs .viminfo.tmp
.bash_profile .emacs .gtkrc second.sh
.viminfz.tmp [lab1@lab1-Lenovo-product:~]$
d) [lab1@lab1-Lenovo-product:~]$ ls –x
a.outcol1.txt college2.txt college.txt coll.txt file.txt fir.sh
firs.sh new.txt one one.txt pgms programs
second.sh [lab1@lab1-Lenovo-product:~]$
6) Command : mv (Move)
a) mv (Move a File to Directory)
Syntax : mv SourceFileDestinationDirectory
[lab1@lab1-Lenovo-product:~]$ mv coll.txt
programs [lab1@lab1-Lenovo-product:~]$ cd
programs [lab1@lab1-Lenovo-product:~]$ ls
coll.txt shellprogram
[lab1@lab1-Lenovo-
product:~]$
b) mv (Move Contents of one File to Another File)
Syntax : mv SourceFileDestinationFile
[lab1@lab1-Lenovo-product:~]$ cat one.txt
coll.txt
[lab1@lab1-Lenovo-product:~]$
11) Command : head (Prints required no. of lines in the File Counting
from the Beginning of the File)
Syntax : head –n filename
13) Command : who (Displays the Users Who Logged into the
System) [lab1@lab1-Lenovo-product:~]$ who
csepts/2 Apr 15 13:34 (192.168.1.21)
itpts/1 Apr 15 15:10 (192.168.1.69)
[lab1@lab1-Lenovo-product:~]$
Command : who am i (Displays the Name of the Current User of
this System)
[lab1@lab1-Lenovo-product:~]$ who
am i itpts/1 Apr 15 15:10
(192.168.1.69)
[lab1@lab1-Lenovo-product:~]$
26 27 28
16) Command : wc (Counts the No. of Chars, Bytes, lines, Chars in the
Longest Line)
[lab1@lab1-Lenovo-product:~]$ wc -m
college.txt 300 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -c
college.txt 300 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -l
college.txt 11 college.txt
[lab1@lab1-Lenovo-product:~]$ wc -L
college.txt 44 college.txt
[lab1@lab1-Lenovo-product:~]$
17) Command : grep (Displays a Line from the file Containing the Given
String)
Syntax :grep “String” filename
Syntax :grep–i “String” filename
i – Ignore Case of the Given String
[lab1@lab1-Lenovo-product:~]$ cat
one.txt Welcome to College of
Engineering
Delhi
IT
Dept
Computer Practices Laboratory
[lab1@lab1-Lenovo-product:~]$ grep "Rcet" one.txt
Welcome to College of Engineering
[lab1@lab1-Lenovo-product:~]$
cat> fi 1 2 3 6
4536
7890
7890
[lab1@lab1-Lenovo-product:~]$ uniq
filefile.new [lab1@lab1-Lenovo-
product:~]$cat file.new
1236
4536
7890
The standard output from the first command is connected directly to the
standard
input of the second command.
EXPERIMENT 3
LINUX EDITOR
General Information:
About vi:
vi (pronounced vee-EYE, short for “visual”) provides basic text
editing capabilities. Three aspects of vi make it appealing.
1. vi is supplied with all LINUX systems.
2. vi uses a small amount of memory, which allows efficient operation
when the network is busy.
3. vi uses standard alphanumeric keys for commands.
You can use it on virtually any terminal or workstation in existence
without having to worry about unusual keyboard mappings. As a point
of interest, vi is actually a special mode of another UNIX text editor
called ex. Normally you do not need to use ex except in vi mode.
vi commands are case-sensitive, which means that upper-case
and lower-case commands are not the same command. For example, j
moves the cursor down, but J combines two lines into one line.
The word RETURN represents the action of pressing RETURN
key. ESC indicates pressing the ESCAPE key. Also, sometimes you will
see a keystroke like CTRL-F. CTRL-F means you hold down the key
marked CONTROL or CTRL, and press F. The CTRL key acts in a
manner similar to the SHIFT key.
Starting vi:
To start vi, enter:
vifilename RETURN
Where filename is the name of the file you want to edit. If the file does
not exist, vi will create it for you. You can also start vi without giving any
filename. In this case, vi will ask for one when you quit or save your
work.
Command Mode and Input Mode:
vi has two modes,
1. command mode
2. input mode
In command mode, characters you type perform actions like
moving the cursor, cutting or copying text, or searching for some
particular text. In input mode, you type to insert or overwrite text. When
you start vi, it is in command mode.
To switch from command to input mode, press the “i” key (you do
not need to press RETURN) Vi lets you insert text beginning at the
current cursor location. To switch back to command mode, press ESC.
You can also use ESC to cancel an unfinished command in command
mode. Unfortunately, vi does not normally indicate which mode you are
in. The next exercise turns on a mode indicator. If you are uncertain
about the current mode, you can press ESC a few times. When vi
beeps, you have returned to command mode.
To Know the Current Mode:
Before you start typing text, the command below activates the
modeline indicator. You are not required to use it, but it tells you
whether you are in command or input mode.
Type:
:setshowmode RETURN
Nothing appears to change. When you are in command mode, there
is
no indicator, but if you enter input mode, one will appear in the bottom
right- hand corner of the window.
Line Numbers:
Many vi commands use line numbers, which simply count the
number of RETURN characters in a file. You can cut and copy text by
line number or jump to a certain line. Line numbers
can be useful when you ritive error messages during program
compilation. Frequently compilers will print the line number, so you can
use vi to jump to the appropriate line and look for the error.
Exercise to display the line numbers, enter the following command:
:set number RETURN
This command will immediately display the line numbers in the left
margin of your vi window.
Vi Commands – A Quick View:
Command Meaning
Vi Commands – A Quick
Review Vi Commands Used To Edit Files
Positioning The Cursor:
Command Meaning
Command Meaning
echoed overhead and shook the clouds, even the ground rumbled as
each clap loudly exploded.
Glancing back, I saw an ocean rising behind us. It just wouldn’t stop
raining. Our weathered tent was a poor shelter tonight. As a lightning
bolt flashes over the hills, we made out a small cave on the
mountainside. A safe haven, thought I.Our heavens fell down, but just
up ahead lay safety.
After entering this text, press ESC to return to command mode.
Notice that the mode line clears,
too Example 2:
Move to the line “Our heavens fell...” and press A to append text at the
end of the line. Then type (the symbol -- means a space
character):
--We crawled in, and wept. ESC
Next go to the line “in foot and hand...” and open a new line below it.
Press: o to start open mode, and observe that vi creates a new line for
text. Type: Take a step and fall. ESC
Deleting Text:
Command Meaning
Command Meaning
character
Command Meaning
Command Meaning
P Same as above
Command Meaning
Command Meaning
Command Meaning
Command Meaning
import
java.text.ParseException;
time\n");
Output
ETCS-304
Operating System GGSIPU ETCS-304
import
java.util.*; public
class SJF {
System.out.println("Before Arrange...");
System.out.println("Process ID\tArrival Time\tBurst
Time"); for (int i = 0; i < num; i++) {
System.out.printf("%d\t\t%d\t\t%d\n",mat[i][0], mat[i][1], mat[i][2]);
}
arrangeArrival(num, mat);
completionTime(num, mat);
System.out.println("Final Result...");
System.out.println("Process ID\tArrival Time\tBurst"
+"
Time\tWaiting Time\tTurnaround
Time"); for (int i = 0; i < num;
i++) {
System.out.printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\n",
mat[i][0], mat[i][1], mat[i][2], mat[i][4], mat[i][5]);
}
sc.close();
}
}
Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
import java.util.Scanner;
int x,n,p[],pp[],bt[],w[],t[],awt,atat,i;
p = new int[10];
pp = new
int[10]; bt =
new int[10]; w
= new int[10]; t
= new int[10];
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(pp[i]>pp[j])
{
x=pp[i];
pp[i]=pp[j]
; pp[j]=x;
x=bt[i];
bt[i]=bt[j];
bt[j]=x;
x=p[i];
p[i]=p[j];
p[j]=x;
}
}
}
w[0]=0;
awt=0;
t[0]=bt[0];
atat=t[0];
for(i=1;i<n;i+
+)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+bt[i];
atat+=t[i];
}
}
}
Output
public class RR
{
static void findWaitingTime(int processes[], int
n, int bt[], int wt[], int quantum)
{
int rem_bt[] = new
int[n]; for (int i = 0 ; i < n
; i++)
rem_bt[i] = bt[i];
int t = 0;
while(true
)
{ boolean done =
true; for (int i = 0 ; i <
n; i++)
{
if (rem_bt[i] > 0)
{
done = false; // There is a pending process
else
{
t = t + rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
}
}
}
if (done ==
true) break;
}
}
static void findTurnAroundTime(int processes[], int
n, int bt[], int wt[], int tat[])
{
for (int i = 0; i < n ;
i++) tat[i] = bt[i] +
wt[i];
}
static void findavgTime(int processes[], int n, int bt[], int quantum)
{
int wt[] = new int[n], tat[] = new
int[n]; int total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt, quantum);
}
}
Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
import java.io.*;
public class PageReplacementTechniques {
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
int n, page[], f, frames[], faults, count;
double rate;
void
reset()
{
int j;
for(j=0;j<f;j++
)
frames[j]=0
; faults=0;
count=1;
}
void
fifo()
{
int i,j,k=0;
reset();
boolean
found=false;
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(page[i]==frames[j])
found=true;
}
if(found==false)
{
frames[k]=page[i
]; if(k==f-1)
k=0;
else
k++;
faults++;
}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}
void
lru()
{
int i,j,duration[],max;
reset();
duration=new int[f];
boolean
found=false;
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
duration[j]++
; for(j=0;j<f;j++)
{
if(page[i]==frames[j])
{
found=true;
duration[j]=0
;
}
}
if(found==false)
{
max=0;
for(j=0;j<f;j++
)
{
if(duration[j]>duration[max]
) max=j;
}
frames[max]=page[
i]; duration[max]=0;
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
faults++;
}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}
void
opt()
{
int i,j=0,k,duration[],max,flag[];
reset();
duration=new int[f];
flag=new int[f];
boolean
found=false;
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
flag[j]=0;
duration[j]=n
;
}
for(k=i+1;k<n;k++)
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
{
for(j=0;j<f;j++)
if(page[k]==frames[j]&&flag[j]==0)
{
duration[j]=k
; flag[j]=1;
}
}
for(j=0;j<f;j++)
if(page[i]==frames[j])
found=true
; if(found==false)
{
max=0;
for(j=0;j<f;j++
)
{
if(duration[j]>duration[max]
) max=j;
if(frames[j]<0)
{
max=j
;
break
;
}
}
frames[max]=page[i];
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
faults++;
}
display();
found=fals
e;
}
System.out.println("Number of page faults = "+faults);
System.out.println("Fault rate = "+(faults*1.0/n));
}
void display()
{
int i;
System.out.print("Page frame "+count+"
:"); for(i=0;i<f;i++)
{
if(frames[i]==-1)
System.out.print(" -");
else
System.out.print(" "+frames[i]);
}
System.out.print("\n")
; count++;
}
int option;
String
choice;
PageReplacementTechniques p=new
PageReplacementTechniques(); p.read();
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
do
{
System.out.println("Menu");
System.out.println("1. FIFO");
System.out.println("2. LRU");
System.out.println("3. OPT");
System.out.println("Enter option");
option=Integer.parseInt(input.readLine());
switch(option)
{
case 1: p.fifo();
break;
case 2: p.lru();
break;
case 3: p.opt();
break;
default: System.out.println("Invalid input");
}
System.out.println("Press Y to continue");
choice=input.readLine();
}
while(choice.compareToIgnoreCase("y")==
0 );
Output
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
import java.io.*;
public class MemoryAllocationTechniques {
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in));
int n, page[], f, frames[], faults, count;
double rate;
bestIdx = j;
else if (blockSize[bestIdx] >
blockSize[j]) bestIdx = j;
}
}
if (bestIdx != -1)
{
allocation[i] = bestIdx;
blockSize[bestIdx] -= processSize[i];
}
}
blockSize[j] -= processSize[i];
break;
}
}
}
wstIdx = j;
else if (blockSize[wstIdx] <
blockSize[j]) wstIdx = j;
}
}
if (wstIdx != -1)
{
allocation[i] = wstIdx;
blockSize[wstIdx] -=
processSize[i];
}
}
break;
case
2:
int blockSize2[] = {120, 850, 150, 400, 900};
int processSize2[] = {183, 512, 96,
386}; int m2 = blockSize2.length;
int n2 = processSize2.length;
firstFit(blockSize2, m2, processSize2,
n2); break;
case 3:
int blockSize3[] = {120, 850, 150, 400, 900};
int processSize3[] = {183, 512, 96,
386}; int m3 = blockSize3.length;
int n3 = processSize3.length;
worstFit(blockSize3, m3, processSize3,
n3); break;
default: System.out.println("Invalid input");
}
System.out.println("Press Y to continue");
choice=input.readLine();
}
while(choice.compareToIgnoreCase("y")==0);
Outpu
t
import java.util.concurrent.Semaphore;
class RWP {
if(readCount == 0) {
writeLock.release
();
}
readLock.release();
} catch (InterruptedException e) {
System.out.println(e.getMessage()
);
}
}
}
Output
class BA
{
static int P = 5;
static int R = 3;
static void calculateNeed(int need[][], int
maxm[][], int allot[][])
{
for (int i = 0 ; i < P ;
i++) for (int j = 0 ; j <
R ; j++)
need[i][j] = maxm[i][j] - allot[i][j];
}
int count = 0;
while (count <
P)
{
boolean found = false;
for (int p = 0; p < P;
p++)
{
if (finish[p] == false)
{
int j;
for (j = 0; j < R; j++)
if (need[p][j] >
work[j]) break;
if (j == R)
{
for (int k = 0 ; k < R ;
k++) work[k] +=
allot[p][k];
safeSeq[count++] =
p; finish[p] = true;
found = true;
}
}
}
if (found == false)
{
Ashish kumar (20318002718)
Operating System GGSIPU ETCS-304
return true;
}
public static void main(String[] args)
{
int processes[] = {0, 1, 2, 3, 4};
int avail[] = {3, 3, 2};
int maxm[][] = {{7, 5, 3}, {3, 2, 2},{9, 0, 2}, {2, 2, 2}, {4, 3, 3}};
int allot[][] = {{0, 1, 0}, {2, 0, 0}, {3, 0, 2}, {2, 1, 1}, {0, 0, 2}};
Outpu
t