Professional Documents
Culture Documents
Jawaharlal Nehru Engineering College: Laboratory Manual
Jawaharlal Nehru Engineering College: Laboratory Manual
Laboratory Manual
Operating System
For
1
FOREWORD
As a student, many of you may be wondering with some of the questions in your
mind regarding the subject and exactly what has been tried is to answer through this
manual.
As you may be aware that MGM has already been awarded with ISO 9001:2000
certification and it is our endure to technically equip our students taking the advantage of
the procedural aspects of ISO 9001:2000 Certification.
Faculty members are also advised that covering these aspects in initial stage itself,
will greatly relived them in future as much of the load will be taken care by the
enthusiasm energies of the students once they are conceptually clear.
Dr. S.D.Deshmukh
Principal
2
LABORATORY MANUAL CONTENTS
This manual is intended for the Third year students of Computer Science and
Engineering in the subject of Operating System. This manual typically contains
practical/Lab Sessions related Operating System covering various aspects related the
subject to enhanced understanding.
Students are advised to thoroughly go through this manual rather than only topics
mentioned in the syllabus as practical aspects are the key to understanding and
conceptual visualization of theoretical aspects covered in the books.
3
DOs and DONTs in Laboratory:
1. Make entry in the Log Book as soon as you enter the Laboratory.
2. All the students should sit according to their roll numbers starting from their left to
right.
3. All the students are supposed to enter the terminal number in the log book.
5. All the students are expected to get at least the algorithm of the program/concept
to be implemented.
1. Submission related to whatever lab work has been completed should be done during
the next lab session. The immediate arrangements for printouts related to submission on
the day of practical assignments.
2. Students should be taught for taking the printouts under the observation of lab teacher.
4
SUBJECT INDEX
5
1. Simulation of Copy command
Aim: - Simulation of Copy command i.e. to copy the contents of one file to another
file.
COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination] [/A | /B]] [/V] [/Y
| /-Y]
destination Specifies the directory and/or filename for the new file(s).
By using Command Line Arguments, accept the source filename and destination
filename. These will be passed as an argument to the program and source file will be read
copied to the destination file.
6
Procedure:
1) Create two file pointers.
2) Read source and destination file names.
3) Open files using file handling commands.
4) Using a while loop read characters and transfer them to the destination file.
5) Close the files.
6) Print a message for confirmation.
Conclusion: - Hence, by using command line arguments we are simulating the copy
command.
7
2. Simulation of MORE command
Aim: - Simulation of More command i.e to display the contents of the file on the
screen page wise.
Output: - The contents of the file will be printed page wise on the screen.
Procedure: -
1) Open the file that is to be viewed.
2) Two types of counter variables are used, one used for counting the total no. of
lines & other to keep watch on the condition that the no. of lines become 25.
3) Reset the value by printing M or More.
Press any key to continue.
4) Finally total no. of lines are printed.
8
3. Implementation of First Come First Serve algorithm for
Processor scheduling.
This code implements the First come First Served Scheduling Algorithm. It gets the process
name, burst time for each process. Calculates and displays the average turnaround time and
waiting time. Then it will display the Gantt chart.
Procedure:
1) Accept values for processes and burst time.
2) Display in a table format
3) Compare the burst time and accordingly make a Gantt chart.
4) Also, calculate the average waiting time.
Advantages:
simple
9
easy to understand
first come first served
Disadvantages:
This scheduling method is nonpreemptive, the process will run until it finishes.
Because of this nonpreemptive scheduling, short processes which are at the back
of the queue have to wait for the long process at the front to finish
Conclusion: - Hence, we have studied the First Come First Served Scheduling Algorithm.
10
4. Implementation of Shortest Job first, a priority algorithm
for Processor scheduling.
P2 P1 P0
0 2 5 29
Procedure:
1) Accept values for processes and burst time.
2) Display in a table format
3) Compare the burst time and accordingly make a Gantt chart.
4) Also, calculate the average waiting time.
Advantage:
11
Waiting time is minimal.
Disadvantage:
The real difficulty with the SJF algorithm is knowing the length of the next CPU
request.
Conclusion: - Hence, we have studied the Shortest Job First Scheduling Algorithm.
12
5. Implementation of Round Robin scheduling, a priority
algorithm for Processor scheduling.
P0 P1 P2 P0 P1 P0 P1 P0
0 5 10 12 17 22 27 30 35
13
= 14 msecs.
Advantage-
Disadvantage-
Procedure:
Conclusion: - Hence, we see that Round Robin Scheduling Algorithm is very fair and no
starvation occurs.
14
6. Study of deadlock and Bankers Algorithm
One reason this algorithm is not widely used in the real world is because to use it
the operating system must know the maximum amount of resources that every process is
going to need at all times. Therefore, for example, a just-executed program must declare
up-front that it will be needing no more than, say, 400K of memory. The operating
system would then store the limit of 400K and use it in the deadlock avoidance
calculations.
The banker is a conservative loaner. Every time that a process makes a request of
for a resource to be ``loaned'' the banker takes a careful look at the bank books and
attempts to determine whether or not a deadlock state could possibly arise in the future if
the loan request is approved.
This determination is made by ``pretending'' to grant the request and then looking
at the resulting post-granted request system state. After granting a resource request there
15
will be an amount of that resource left free in the system, f. Further, there may be other
processes in system. We demanded that each of these other processes state the maximum
amount of all system resources they needed to terminate up-front so, therefore, we know
how much of each resource every process is holding and has claim to.
If the banker has enough free resource to guarantee that even one process can
terminate, it can then take the resource held by that process and add it to the free pool. At
this point the banker can look at the (hopefully) now larger free pool and attempt to
guarantee that another process will terminate by checking whether its claim can be met.
If the banker can guarantee that all jobs in system will terminate, it approves the loan in
question.
If, on the other hand, at any point in the reduction the banker cannot guarantee
any processes will terminate because there is not enough free resource to meet the
smallest claim, a state of deadlock can ensue. This is called an unsafe state. In this case
the loan request in question is denied and the requesting process is usually blocked.
Procedure:
1) Enter number of processes with their need.
2) Find out whether allocated resources are greater than required resources.
3) If allocated resources are greater than required resources then it in safe state or
else it an unsafe state.
17
18
7. Program for determining physical memory of a disk
Procedure:
1) Invoke the dos_getdiskfree() function for current drive.
2) For available bytes take the product of aval_cluster, bytes_per_sector and
sector_per_cluster.
3) For total space get the product of total_cluster, bytes_per_sector and
sector_per_cluster.
19
8. Case study of Windows -NT
20
9. Case study of LINUX
21
Frequently Asked Questions in OS:
1) Definition of OS.
2) Difference between time sharing and multitasking systems.
3) What is process scheduling?
4) What are the different scheduling policies?
5) What is the need for memory management?
6) Different memory management techniques.
7) What is paging?
8) What do you mean by base n limit registers?
9) What is segmentation?
10) What are the different page replacement policies?
11) How does interprocess communication occur?
12) What is a race condition?
13) What do you mean by critical section?
14) Explain scheduling.
15) What is contiguous memory allocation?
16) What is a thread?
17) How can these be implemented in kernel space?
18) What is virtual address space?
19) What is virtual memory and physical memory?
20) What are different process states?
21) Explain LIFO, FIFO algorithms?
22) Explain priority scheduling.
23) What are deadlocks?
24) How do you handle deadlocks?
25) Explain the terms
a) Thrashing
b) Compaction
c) Internal/external fragmentation
d) Demand paging
e) Disk scheduling algorithms
f) Disk formatting
g) Directory structure
22
h) Overlays
i) Process control block
j) Monitors
k) Swapping
l) Encryption
m) Virtual machines
n) Inverted page tables
o) Device driver
Quiz should be conducted on tips in the laboratory, recent trends and subject knowledge
of the subject. The quiz questions should be formulated such that questions are normally
are from the scope outside of the books. However twisted questions and self formulated
questions by the faculty can be asked but correctness of it is necessarily to be thoroughly
checked before the conduction of the quiz.
Teacher should oral exams of the students with full preparation. Normally, the objective
questions with guess are to be avoided. To make it meaningful, the questions should be
such that depth of the students in the subject is tested Oral examinations are to be
conducted in co-cordial environment amongst the teachers taking the examination.
Teachers taking such examinations should not have ill thoughts about each other and
courtesies should be offered to each other in case of difference of opinion, which should
be critically suppressed in front of the students.
Basic honesty in the evaluation and marking system is absolutely essential and in the
process impartial nature of the evaluator is required in the examination system to become
popular amongst the students. It is a wrong approach or concept to award the students by
way of easy marking to get cheap popularity among the students to which they do not
23
deserve. It is a primary responsibility of the teacher that right students who are really
putting up lot of hard work with right kind of intelligence are correctly awarded.
The marking patterns should be justifiable to the students without any ambiguity and
teacher should see that `students are faced with unjust circumstances.
24
FCFS:
#include < stdio.h>
#include < conio.h>
struct process
{
int pid;
int burst;
int wait;
};
void main()
{
struct process p[5];
int i, j, wait=0;
float twait;
clrscr();
for(i=1;i<=5;i++)
{
p[i].pid=i;
printf("\nprocess p%d\n",i);
printf("\nenter burst time\n");
scanf("%d",&p[i].burst);
}
printf("\nprocess\t\tburst time\t\twaiting time\n");
for(i=1;i<=5;i++)
{
p[i].pid=i;
p[i].wait=wait;
printf("\nP%d\t\t%d\t\t\t\t %d",p[i].pid, p[i].burst,p[i].wait);
wait = wait + p[i].burst;
}
twait=wait;
printf("\n\naverage waiting time= %f",(twait/5));
getch();
}
25
SJF
# include < stdio.h>
# include < conio.h>
struct process
{
int pid ;
int burst ;
int wait ;
};
void main()
{
struct process p[5] , temp ;
int i,j,wait=0 ;
float twait;
clrscr();
for(i=0;i<5;i++)
{
p[i].pid = i+1 ;
printf("\nprocess p%d\n",i+1) ;
printf("\nenter burst time\n");
scanf("%d",&p[i].burst);
}
for(i=0;i<5;i++)
{ for(j=0;j<5;j++)
{
if(p[j].burst>p[i].burst)
{
temp=p[i];
p[i]=p[j] ;
p[j]=temp;
}
}
}
printf("\nprocess\t\tburst time\t\twaiting time\n");
for(i=0;i<5;i++)
{
p[i].wait=wait ;
printf("\np%d\t\t%d\t\t\t%d\n",p[i].pid,p[i].burst,p[i].wait);
wait = wait + p[i].burst ;
}
twait=wait;
printf("\n\n average waiting time= %f",(twait/5));
getch();
}
26