Lab Manual: Oriental College of Technology, Bhopal
Lab Manual: Oriental College of Technology, Bhopal
BHOPAL
LAB MANUAL
Programme : BE
Semester : IV
AIM: To study the difference between Microsoft windows and Linux Operating System.
THEORY:
EXPERIMENT – 2
THEORY:
The Linux file system is the structure in which all the information on your computer is stored. Files
are organized within a hierarchy of directories. Each directory can contain files, as well as other
directories.
If you were to map out the files and directories in Linux, it would look like an upside-down tree. At
the top is the root directory, which is represented by a single slash ( / ). Below that is a set of common
directories in the Linux system, such as bin, dev, home, lib , and tmp , to name a few. Each of those
directories, as well as directories added to the root, can contain subdirectories.
Some of the Linux directories that may interest you include the following:
/bin - Contains common Linux user commands, such as ls, sort , date , and chmod .
/boot - Has the bootable Linux kernel and boot loader configuration files (GRUB).
/dev - Contains files representing access points to devices on your systems. These include
terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM ( ram* ), and
CD-ROM ( cd* ). (Applications normally access these devices directly through the device
files, but end users rarely access them directly.)
/etc - Contains administrative configuration files.
/home - Contains directories assigned to each user with a login account.
/media - Provides a location for mounting devices, such as remote file systems and removable
media (with directory names of cdrom , floppy , and so on). In Fedora and RHEL, many
removable media are mounted automatically in this directory when the media is inserted (CD
or DVD) or connected (USB pen drives or cameras ).
/proc - Provides a mechanism for the kernel to send information to processes.
/root - Represents the root user's home directory.
/sbin - Contains administrative commands and daemon processes.
/sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to contain files
for getting hardware status and reflecting the system's device tree as it is seen by the kernel. It
pulls many of its functions from /proc .
/tmp - Contains temporary files used by applications.
/usr - Contains user documentation, games , graphical files (X11), libraries (lib), and a variety
of other user and administrative commands and files.
/var - Contains directories of data used by various applications. In particular, this is where you
would place files that you share as an FTP server ( /var/ftp ) or a Web server ( /var/www ). It
also contains all system log files ( /var/log ). In time, FTP, HTTP, and similar services will
move to the /srv directory to adhere to the Linux Standards Base (
www.freestandards.org/spec ).
COMMAND :
1.Date Command :
Syntax :
$date
$date +%ch
Options :
a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .
2.Calender Command :
This command is used to display the calendar of the year or the particular month of
calendar year.
Syntax :
a.$cal <year>
b.$cal <month> <year>
Here the first syntax gives the entire calendar for given year & the second Syntax gives
the calendar of reserved month of that year.
3.Echo Command :
4.Banner Command :
5.’who’ Command :
It is used to display who are the users connected to our computer currently.
Options : -
6.’who am i’ Command :
Syntax : $who am i
9.’CLEAR’ Command :
Syntax : $clear
10.’MAN’ Command :
It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .
11.LIST Command :
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.
Syntax : $pwd
2.MKDIR Command :
3.CD Command :
4.RMDIR Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>
1.CREATE A FILE :
2.DISPLAY A FILE :
To display the content of file mentioned we use CAT command without „>‟ operator.
3.COPYING CONTENTS :
To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.
Options :
Syntax :
$cat –n <filename>
4.SORTING A FILE :
To sort the contents in alphabetical order in reverse order.
Syntax :
$sort <filename >
Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>
6.MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax :
$ mv <source filename> <destination filename>
7.REMOVE Command :
To permanently remove the file we use this command .
Syntax :
$rm <filename>
8.WORD Command :
To list the content count of no of lines , words, characters .
Syntax :
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.
Syntax: $head<filename>
TAIL : This command is used to display the last ten lines of file.
Syntax: $tail<filename>
PAGE : This command shows the page by page a screen full of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.
MORE : It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.
Syntax: $more<filename>
Syntax: $sort<filename>
PIPE : It is a mechanism by which the output of one command can be channelled into the
input of another command.
INPUT :
Valid Input-
Valid Output-
Invalid Input-
Invalid Output-
VIVA QUESTION :
EXPERIMENT – 3
AIM:
To study the various File Acess Permission and different types of users in LINUX
THEORY:
File ownership is an important component of LINUX that provides a secure method for storing files.
Every file and directory in LINUX has the following attributes:
Owner permissions: The owner's permissions determine what actions the owner of the file
can perform on the file.
Group permissions: The group's permissions determine what actions a user, who is a
member of the group that a file belongs to, can perform on the file.
Other (world) permissions: The permissions for others indicate what action all other users
can perform on the file.
1. Read:Grants the capability to read ie. view the contents of the file and directory .
2. Write:Grants the capability to modify, or remove the content of the file and directory .
3. Execute:User with execute permissions can run a file as a program.But in case of directory , it
does not mean anything only traverse permission .
r W X R __ X r __ X
__
File Permission for the owner Permission of the Permission for the
Type of file group to which the rest of users
files belongs
CHANGING PERMISSIONS:
To change file or directory permissions, you use the chmod (change mode) command. There
are two ways to use chmod: symbolic mode and absolute mode.
The easiest way for a beginner to modify file or directory permissions is to use the symbolic
mode. With symbolic permissions you can add, delete, or specify the permission set you want
by using the operators in the following table.
u user
g group
o other
a all
r read
w write
x execute
The second way to modify permissions with the chmod command is to use a number to
specify each set of permissions for the file.
Each permission is assigned a value, as the following table shows, and the total of each set of
permissions provides a number for that set.
0 No permission ---
1 Execute permission --x
2 Write permission -w-
Execute and write permission: 1 (execute) + 2
3 -wx
(write) = 3
4 Read permission r--
Read and execute permission: 4 (read) + 1
5 r-x
(execute) = 5
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
All permissions: 4 (read) + 2 (write) + 1 (execute)
7 rw
=7
While creating an account on Unix, it assigns a owner ID and a group ID to each user. All the
permissions mentioned above are also assigned based on Owner and Groups.
Two commands are available to change the owner and the group of files:
1. chown: The chown command stands for "change owner" and is used to change the
owner of a file.
2. chgrp: The chgrp command stands for "change group" and is used to change the
group of a file.
Changing ownership:
syntax :
The value of user can be either the name of a user on the system or the user id (uid) of a user
on the system.
syntax :
INPUT:
Valid input: Create a directory and put some files into it. Now play about with removing
various permissions from yourself on that directory and see what you can and can't do.
Valid output:
Invalid input:
chmode u + g file1
EXPERIMENT – 4
AIM: To write a C program to implement the CPU scheduling algorithm for FIRST COME
FIRST SERVE.
THEORY:
FCFS:
CPU scheduler will decide which process should be given the CPU for its execution.For this
it use different algorithm to choose among the process. one among that algorithm is fcfs
algorithm.
In this algorithm the process which arrive first is given the cpu after finishing its request only
it will allow cpu to execute other process.
ALGORITHM:
OUTPUT:
EXPERIMENT – 5
AIM: Write a C program to implement Shortest Job First Algorithm.
THEORY:
SJF:
This algorithm associates with each process the length of the process's next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.
If the next CPU bursts of two processes are the same, FCFS scheduling is used.
2 .ALGORITHM:
OUTPUT:
EXPERIMENT – 6
AIM: To write a C program to implement Non Preemptive Priority Scheduling Algorithm.
THEORY:
PREEMPTIVE PRIORITY:
Priority scheduling is a non-preemptive algorithm and one of the most common
scheduling algorithms in batch systems.
Each process is assigned a priority. Process with highest priority is to be executed first
and so on.
Processes with same priority are executed on first come first served basis.
Priority can be decided based on memory requirements, time requirements or any
other resource requirement.
P0 9-0=9
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
ALGORITHM:
Step:4 If in FCFS both arrival times are same then, SJF is used to break the tie.
Step:5 Repeat the step 1 to 4 until ready queue is empty. Step 6: Calculate Waiting time and
Turnaround time of individual Process.
PROGRAM:
INPUT:
OUTPUT:
EXPERIMENT – 7
ALGORITHM:
PROGRAM:
INPUT:
OUTPUT:
EXPERIMENT – 8
THEORY:
Example:
Let us consider a set of processes P1, P2, P3 having priorities ranging from 1 to 3. Let us
assume that 1 is the highest priority whereas 3 is the least priority. Let us also assume that p1
arrive first and P3 arrives in the last.
P1 P2 P3 P2 P1
0 1 2 4 8 17
ALGORITHM:
Step 2: Assign the process to the CPU according to the arrival time, lower arrival time
process will get the CPU first than higher arrival time process.
Step 3: Assign the process to the CPU according to the priority, higher priority process will
get the CPU first than lower priority process while comparing with the arrival time.
Step 3: If two processes have similar priority then FCFS is used to break the tie.
Step 5: Calculate Waiting time and Turnaround time of individual Process. Step 6: Calculate
Average waiting time and Average Turnaround time.
PROGRAM:
INPUT:
OUPUT:
EXPERIMENT – 9
AIM: Write a C program to implement the CPU scheduling mechanisms such as Round
Robin Scheduling.
RR :
The round-robin (RR) scheduling algorithm is designed especially for time-sharing systems.
It is similar to FCFS scheduling . A small unit of time, called a time quantum or time slice, is
defined. A time quantum is generally from 10 to 100 milliseconds. The ready queue is treated
as a circular queue.
3.ALGORITHM:
PROGRAM:
INPUT:
OUTPUT:
EXPERIMENT – 10
There are some Philosophers whose work is just thinking and eating. Let there are 5 (for
example) philosophers. They sat at a round table for dinner. To complete dinner each must
need two Forks (spoons). But there are only 5 Forks available (Forks always equal to no. of
Philosophers) on table. They take in such a manner that, first take left Fork and next right
Fork. But problem is they try to take at same time. Since they are trying at same time, Fork 1,
2, 3, 4, 5 taken by Philosopher 1, 2, 3, 4, 5 respectively (since they are left side of each). And
each one tries to ta ke right side Fork. But no one found available Fork. And also that each
one thinks that someone will release the Fork and then I can eat. This continuous waiting
leads to Dead Lock situation.
ALGORITHM:
PROGRAM:
INPUT:
OUTPUT:
EXPERIMENT – 11
THEORY:
Imagine a scenario in which there exists two Destinct processes both operating on a single
shared data area. One process, the Producer inserts information into the data area whilst the
other process, the Consumer, removes information from that same area. In order for the
Producer to insert information into the data area, there must be enough space. The Producer's
sole function is to insert data into the data-area, it is not allowed to remove any data from the
area. Similarly ormation there in the first place. Once again, the sole function of the
Consumer is to remove data from the data area. If no data is present then the Consumer is not
allowed to insert some data of it's own to later be removed by itself.
In short, the Producer relies on the Consumer to make space in the data-area so that it may
insert more information whilst at the same time, the Consumer relies on the Producer to insert
information into the data area so that it may remove that information. It therefore follows that
a mechanism is required to allow the Producer and Consumer to communicate so that they
know when it is safe to attempt to write or read information from the data-area.
ALGORITHM:
Step 1: Start
Step 2: Define the maximum buffer size.
Step 3:Enter the number of producers and consumers.
Step 4: The producer produces the job and put it in the buffer.
Step 5:The consumer takes the job from the buffer.
Step 6:If the buffer is full the producer goes to sleep.
Step 7:If the buffer is empty then consumer goes to sleep.
Step 8:Stop
PROGRAM:
EXPERIMENT – 12
THEORY:
If one of the people tries editing the file, no other person should be reading or writing at the
same time, otherwise changes will not be visible to him/her.
However if some person is reading the file, then others may read it at the same time.
Precisely in OS we call this situation as the readers-writers problem
Problem parameters:
OUTPUT: