0% found this document useful (0 votes)
4 views

Operating System Lab Manual (3)

The document is a lab manual from Gyan Ganga Institute of Technology and Sciences, Jabalpur, detailing various experiments related to operating systems. It includes programs for CPU scheduling algorithms such as FCFS, SJF, Priority, and Round Robin, along with a simulation for deadlock prevention. Each experiment outlines the aim, algorithm, program code, and expected output.

Uploaded by

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

Operating System Lab Manual (3)

The document is a lab manual from Gyan Ganga Institute of Technology and Sciences, Jabalpur, detailing various experiments related to operating systems. It includes programs for CPU scheduling algorithms such as FCFS, SJF, Priority, and Round Robin, along with a simulation for deadlock prevention. Each experiment outlines the aim, algorithm, program code, and expected output.

Uploaded by

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

GYAN GANGA INSTITUTE OF TECHNOLOGY AND SCIENCES, JABALPUR

LAB MANUAL

Operating System
List of Experiment

S. NO NAME OF THE EXPERIMENTS

1 Write a program to implement FCFS CPU scheduling algorithm.

2 Write a program to implement SJF CPU scheduling algorithm.

3 Write a program to implement Priority CPU Scheduling algorithm.

4 Write a program to implement Round Robin CPU scheduling


algorithm.

5 Write a program to implement Banker’s algorithms

6 Write a program to implement classical inter process communication


problem (producer consumer).

7 Write a program to implement & Compare various page replacement


algorithms.

8 Write a Devices Drivers for any Device or peripheral.


Practical No. 1

FIRST COME FIRST SERVE SCHEDULING

AIM: To write the program to implement CPU & scheduling algorithm for first come first serve scheduling.

ALGORITHM:

1. Start the program.


2. Get the number of processes and their burst time.
3. Initialize the waiting time for process 1 and 0.
4. Process for(i=2;i<=n;i++),wt.p[i]=p[i-1]+bt.p[i-1].
5. The waiting time of all the processes is summed then average value time is calculated.
6. The waiting time of each process and average times are displayed
7. Stop the program

PROGRAM :

#include<stdio.h>
struct process
{

int pid; int bt;


int wt,tt;
}p[10];

int main()

{
int i,n,totwt,tottt,avg1,avg2; clrscr();

printf("enter the no of process \n"); scanf("%d",&n); for(i=1;i<=n;i++)


{
p[i].pid=i;

printf("enter the burst time n"); scanf("%d",&p[i].bt);

}
p[1].wt=0; p[1].tt=p[1].bt+p[1].wt; i=2;
while(i<=n)

{
i=1;
p[i].wt=p[i-1].bt+p[i-1].wt; p[i].tt=p[i].bt+p[i].wt; i ++;

3
}

totwt = tottt = 0;

printf("\n processid \t bt\t wt\t tt\n"); while(i<=n){

printf("\n\t%d \t%d \t%d \t%d",p[i].pid,p[i].bt,p[i].wt,p[i].tt); totwt=p[i].wt+totwt;


tottt=p[i].tt+tottt; i++;}
avg1=totwt/n; avg2=tottt/n; printf("\navg1=%d \t avg2=%d
\t",avg1,avg2)
; getch(); return 0;

OUTPUT:

enter the no of process


3

enter the burst time 2

enter the burst time 4

enter the burst time 6

Process sid bt wt tt

1 2 0 2

2 4 2 6

3 6 6 12

avg1=2 avg2=6

RESULT: Thus the FIFO process scheduling program was executed and verified successfully.
Practical No. 2

Aim: To write a program to implement cpu scheduling algorithm for shortest job first scheduling.

ALGORITHM:

1. Start the program. Get the number of processes and their burst time.
2. Initialize the waiting time for process 1 as 0.
3. The processes are stored according to their burst time.
4. The waiting time for the processes are calculated a follows:
for(i=2;i<=n;i++).wt.p[i]=p[i=1]+bt.p[i-1].
5. The waiting time of all the processes summed and then the average time is calculate
6. The waiting time of each processes and average time are displayed.
7. Stop the program.

PROGRAM:

#include<stdio.h>

#include<conio.h>

struct process

Int pid; int bt;

int wt; int tt;

}p[10],temp; int main()

int i,j,n,totwt,tottt; float avg1,avg2; clrscr();

printf("\nEnter the number of process:\t"); scanf("%d",&n);

for(i=1;i<=n;i++)

{
p[i].pid=i;

printf("\nEnter the burst time:\t"); scanf("%d",&p[i].bt);

for(i=1;i<n;i++){ for(j=i+1;j<=n;j++)

if(p[i].bt>p[j].bt)

temp.pid=p[i].pid;

p[i].pid=p[j].pid; p[j].pid=temp.pid;

temp.bt=p[i].bt;p[i].bt=p[j].bt; p[j].bt=temp.bt;

p[1].wt=0; p[1].tt=p[1].bt+p[1].wt; i=2;

while(i<=n){

p[i].wt=p[i-1].bt+p[i-1].wt;

p[i].tt=p[i].bt+p[i].wt; i++;
i=1;

totwt=tottt=0;

printf("\nProcess id \tbt \twt \ttt"); while(i<=n){

printf("\n\t%d \t%d \t%d t%d\n",p[i].pid,p[i].bt,p[i].wt,p[i].tt); totwt=p[i].wt+totwt;

tottt=p[i].tt+tottt; i++;

} avg1=totwt/n; avg2=tottt/n;

printf("\nAVG1=%f\t AVG2=%f",avg1,avg2); getch();

return 0; }

OUTPUT:

enter the number of process 3

enter the burst time: 2

enter the burst time: 4

enter the burst time: 6

processid bt wt tt

1 2 0 2

2 4 2 6

3 6 6 12

AVG1=2.000000 AVG2=6.000000
Practical No 3
Aim: To write a ‘C’ program to perform priority scheduling.

ALGORITHM:

1. Start the program.


2. Read burst time, waiting time, turn the around time and priority.
3. Initialize the waiting time for process 1 and 0.
4. Based up on the priority process are arranged
5. The waiting time of all the processes is summed and then the average waiting time
6. The waiting time of each process and average waiting time are displayed based on the priority.
7. Stop the program.

PROGRAM:

#include<stdio.h>
#include<conio.h>
struct process
{
int pid; int bt; int wt; int tt; int prior;
}
p[10],temp; int main()
{
int i,j,n,totwt,tottt,arg1,arg2; clrscr();
printf("enter the number of process"); scanf("%d",&n);
for(i=1;i<=n;i++)
{
p[i].pid=i;
printf("enter the burst time"); scanf("%d",&p[i].bt); printf("\n enter the priority");
scanf("%d",&p[i].prior);
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i].prior>p[j].prior)
temp.pid=p[i].pid; p[i].pid=p[j].pid;
p[j].pid=temp.pid; temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt; temp.prior=p[i].prior; p[i].prior=p[j].prior; p[j].prior=temp.prior;
}
}
}
p[i].wt=0;
p[1].tt=p[1].bt+p[1].wt; i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt; i++;
}
i=1;
totwt=tottt=0;
printf("\n process to \t bt \t wt \t tt"); while(i<=n)
{
printf("\n%d\t %d\t %d\t %d\t",p[i].pid,p[i].bt,p[i].wt,p[i].tt); totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;
}
arg1=totwt/n; arg2=tottt/n;
printf("\n arg1=%d \t arg2=%d\t",arg1,arg2);
getch();
return 0;
}

OUTPUT:

enter the no of process:3


enter the burst time:2 enter
the priority:3
enter the burst time:4
enter the priority:1
enter the burst time:6
enter the priority:2
process to bt wt tt
1 4 0 4 4

2 6 4 10 14

3 2 10 12 22

avg1=4 avg2=8
Practical No. 4

ROUND ROBIN SCHEDULING

Aim: To write a program to implement CPU scheduling for Round Robin Scheduling.

ALGORITHM:
1. Get the number of process and their burst time.
2. Initialize the array for Round Robin circular queue as ‘0’.
3. The burst time of each process is divided and the quotients are stored on the round Robin
array.
4. According to the array value the waiting time for each process and the average time are
calculated as line the other scheduling.
5. The waiting time for each process and average times are displayed.
6. Stop the program.

PROGRAM :

#include<stdio.h>
#include<conio.h>
struct process
{
int pid,bt,tt,wt;
};
int main()
{
struct process x[10],p[30];
int i,j,k,tot=0,m,n;
float wttime=0.0,tottime=0.0,a1,a2;
clrscr();
printf("\nEnter the number of process:\t"); scanf("%d",&n);
for(i=1;i<=n;i++){ x[i].pid=i;
printf("\nEnter the Burst Time:\t"); scanf("%d",&x[i].bt); tot=tot+x[i].bt;
}
printf("\nTotal Burst Time:\t%d",tot); p[0].tt=0;
k=1;
printf("\nEnter the Time Slice:\t"); scanf("%d",&m);
for(j=1;j<=tot;j++)
{
for(i=1;i<=n;i++)
{
if(x[i].bt !=0)
{
p[k].pid=i; if(x[i].bt-m<0)
{
p[k].wt=p[k-1].tt;
p[k].bt=x[i].bt; p[k].tt=p[k].wt+x[i].bt;
x[i].bt=0; k++;
}
else
{
p[k].wt=p[k-1].tt;
p[k].tt=p[k].wt+m;
x[i].bt=x[i].bt-m; k++;
}}}}

printf("\nProcess id \twt \ttt");


for (i=1;i<k;i++)
{
printf("\n\t%d \t%d \t%d",p[i].pid,p[i].wt,p[i].tt);
wttime=wttime+p[i].wt;
tottime=tottime+p[i].tt; a1=wttime/n; a2=tottime/n;
}
printf("\n\nAverage Waiting Time:\t%f",a1);
printf("\n\nAverage TurnAround Time:\t%f",a2); getch();
return 0;

OUTPUT:

enter the no of process3

enter the burst time3

enter the burst time5

enter the burst time7

total burst time : 15

enter the time slice: 2

process id wt tt

1 0 2

2 2 4

3 4 6

1 6 7
process id wt tt

2 7 9

3 9 11

2 11 12

3 12 14

3 14 15

avg waiting time: 21.666666 avg turnaround time: 26.666666

RESULT:

Thus the Round Robin scheduling program was executed and verified successfully.
Practical No.5

SIMULATE ALGORITHM FOR DEADLOCK PREVENTION


ALGORITHM:

1. Start the program


2. Attacking Mutex condition: never grant exclusive access. But this may not be possible for several
resources.
3. Attacking preemption: not something you want to do.
4. Attacking hold and wait condition: make a process hold at the most 1 resource
5. At a time. Make all the requests at the beginning. Nothing policy. If you feel, retry.
6. Attacking circular wait: Order all the resources. Make sure that the requests are issued in the
7. Correct order so that there are no cycles present in the resource graph. Resources
numbered 1 ... n.
8. Resources can be requested only in increasing
9. Order. i.e. you cannot request a resource whose no is less than any you may be holding.
10. Stop the program
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

PROGRAM: (SIMULATE ALGORITHM FOR DEADLOCK PREVENTION)

#include<stdio.h> #include<conio.h>

int max[10][10], alloc[10][10], need[10][10];

int avail[10],i,j,p,r,finish[10]={0},flag=0; int main()

clrscr( );

printf("\n\nSIMULATION OF DEADLOCK PREVENTION");

printf("Enter no. of processes, resources"); scanf("%d%d",&p,&r);printf("Enter allocation matrix");

for(i=0;i<p;i++)

for(j=0;j<r;j++) scanf("%d",&alloc[i]

[j]); printf("enter max matrix");

for(i=0;i<p;i++) /*reading the maximum matrix and availale matrix*/ for(j=0;j<r;j++)

scanf("%d",&max[i][j]); printf("enter available

matrix"); for(i=0;i<r;i++)

scanf("%d",&avail[i]); for(i=0;i<p;i++)

for(j=0;j<r;j++) need[i][j]=max[i][j]-alloc[i][j];

fun(); /*calling function*/ if(flag==0)

if(finish[i]!=1)

printf("\n\n Failing :Mutual exclusion");

for(j=0;j<r;j++)

{ /*checking for mutual exclusion*/ if(avail[j]<need[i][j])

avail[j]=need[i][j];

}fun();

printf("\n By allocating required resources to process %d dead lock is prevented ",i);

printf("\n\n lack of preemption"); for(j=0;j<r;j++)

50
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

if(avail[j]<need[i][j])

avail[j]=need[i][j];

alloc[i][j]=0;

fun( );

printf("\n\n daed lock is prevented by allocating needed resources"); printf(" \n \n failing:Hold and Wait

condition ");

for(j=0;j<r;j++)

if(avail[j]<need[i][j])

avail[j]=need[i][j];

fun( );

printf("\n AVOIDING ANY ONE OF THE CONDITION, U CAN PREVENT DEADLOCK");

getch( );

return 0;

fun()

while(1)

for(flag=0,i=0;i<p;i++)

if(finish[i]==0)

for(j=0;j<r;j++)

51
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

if(need[i][j]<=avail [j])

continue;

else break;

if(j==r)

for(j=0;j<r;j++) avail[j]+=alloc[i][j]; flag=1;

finish[i]=1;

}}

if(flag==0) break;

}return 0;

OUTPUT:
SIMULATION OF DEADLOCK PREVENTION

Enter no. of processes, resources 3, 2 Enter

allocation matrix 2 4 5

345

Enter max matrix4 3 4

561

Enter available matrix2

Failing: Mutual Exclusion

By allocating required resources to process dead is prevented

Lack of no preemption deadlock is prevented by allocating needed resources Failing:

Hold and Wait condition

Practical No. 6
52
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

PRODUCER-CONSUMER PROBLEM USING SEMOPHERES

Aim: To implement producer/consumer problem using semaphore.

ALGORITHM:
1. Declare variable for producer & consumer as pthread-t-tid produce tid consume.
2. Declare a structure to add items, semaphore variable set as struct.
3. Read number the items to be produced and consumed.
4. Declare and define semaphore function for creation and destroy.
5. Define producer function.
6. Define consumer function.
7. Call producer and consumer.
8. Stop the execution.

PROGRAM:

#include<stdio.h>
void main()
{

int buffer[10], bufsize, in, out, produce, consume, choice=0; in = 0;


out = 0;

bufsize = 10;

while(choice !=3)

printf("\n1. Produce \t 2. Consume \t3. Exit");


printf("\nEnter your choice: =");
scanf("%d", &choice); switch(choice)
{

case 1: if((in+1)%bufsize==out)
printf("\nBuffer is Full");
else

printf("\nEnter the value: ");


scanf("%d", &produce); buffer[in] =
produce;
in = (in+1)%bufsize;

53
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

break;

case 2: if(in == out)


printf("\nBuffer is Empty");
else

consume = buffer[out];

printf("\nThe consumed value is %d", consume); out =


(out+1)%bufsize;
}

break;

} } }

OUTPUT:

1. Produce 2. Consume 3. Exit

Enter your choice: 2

Buffer is Empty

1. Produce 2. Consume 3. Exit

Enter your choice: 1

Enter the value: 100

1. Produce 2. Consume 3. Exit

Enter your choice: 2

The consumed value is 100

1. Produce 2. Consume 3. Exit

Enter your choice: 3

RESULT:
54
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

Thus the producer consumer program was executed and verified successfully

55
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

Practical No.7

Aim: Write a program to implement & Compare various page replacement algorithms.

To Simulate FIFO page replacement algorithms.

ALGORITHM:

1. Start the program


2. Read the number of frames
3. Read the number of pages
4. Read the page numbers
5. Initialize the values in frames to -1
6. Allocate the pages in to frames in First in first out order.
7. Display the number of page faults.
8. Stop the program

56
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

Aim: Simulate LRU page replacement algorithms

ALGORITHM:

1. Start
2. Read the number of frames
3. Read the number of pages
4. Read the page numbers
5. Initialize the values in frames to -1
6. Allocate the pages in to frames by selecting the page that has not been used for the longest period of
time.
7. Display the number of page faults.
8. stop

Aim: Optimal page replacement algorithms

ALGORITHM:

1. Start the program

2. Read the number of frames

3. Read the number of pages

4. Read the page numbers

5. Initialize the values in frames to -1

6. Allocate the pages in to frames by selecting the page that will not be used for the longest period
of time.

7. Display the number of page faults.

8. Stop the program

57
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Computer Science & Engineering

PROGRAM:

58
#include<stdio.h>

int n,pg[30],fr[10];

void fifo();

void optimal();

void lru();

void main()

int i,ch;

printf(“\nEnter total number of pages:”);

scanf(“%d”,&n);

printf(“\nEnter sequence:”);

for(i=0;i<n;i++) //accepting sequence

scanf(“%d”,&pg[i]);

do

printf(“\n\tMENU\n”);

printf(“\n1)FIFO”);

printf(“\n2)OPTIMAL”);

printf(“\n3)LRU”);

printf(“\n4)Exit”);

printf(“\nEnter your choice:”);

scanf(“%d”,&ch);

switch(ch)

case 1: fifo();
Gyan Ganga Institute of Technology and Sciences, Jabalpur

break;

case 2: optimal();

break;

case 3: lru();

break;

}while(ch!=4);

getchar();

void fifo()

int i,f,r,s,count,flag,num,psize;

f=0;

r=0;

s=0;

flag=0;

count=0;

printf(“\nEnter size of page frame:”);

scanf(“%d”,&psize);
Gyan Ganga Institute of Technology and Sciences, Jabalpur

for(i=0;i<psize;i++)

fr[i]=-1;

while(s<n)

flag=0;

num=pg[s];

for(i=0;i<psize;i++)

if(num==fr[i])

s++;

flag=1;

break;

if(flag==0)

if(r<psize)

fr[r]=pg[s];

r++;
Gyan Ganga Institute of Technology and Sciences, Jabalpur

s++;

count++;

else

if(f<psize)

fr[f]=pg[s];

s++;

f++;

count++;

else

f=0;

printf(“\n”);

for(i=0;i<psize;i++)

printf(“%d\t”,fr[i]);

printf(“\nPage Faults=%d”,count);
Gyan Ganga Institute of Technology and Sciences, Jabalpur

getchar();

void optimal()

int count[10],i,j,k,fault,f,flag,temp,current,c,dist,max,m,cnt,p,x;

fault=0;

dist=0;

k=0;

printf(“\nEnter frame size:”);

scanf(“%d”,&f);

//initilizing distance and frame array

for(i=0;i<f;i++)

count[i]=0;

fr[i]=-1;

for(i=0;i<n;i++)

flag=0;

temp=pg[i];

for(j=0;j<f;j++)

if(temp==fr[j])
Gyan Ganga Institute of Technology and Sciences, Jabalpur

flag=1;

break;

if((flag==0)&&(k<f))

fault++;

fr[k]=temp;

k++;

else if((flag==0)&&(k==f))

fault++;

for(cnt=0;cnt<f;cnt++)

current=fr[cnt];

for(c=i;c<n;c++)

if(current!=pg[c])

count[cnt]++;

else

break;
Gyan Ganga Institute of Technology and Sciences, Jabalpur

max=0;

for(m=0;m<f;m++)

if(count[m]>max)

max=count[m];

p=m;

fr[p]=temp;

printf(“\n”);

for(x=0;x<f;x++)

printf(“%d\t”,fr[x]);

printf(“\nTotal number of faults=%d”,fault);

getchar();

}
Gyan Ganga Institute of Technology and Sciences, Jabalpur

void lru()

int count[10],i,j,k,fault,f,flag,temp,current,c,dist,max,m,cnt,p,x;

fault=0;

dist=0;

k=0;

printf(“\nEnter frame size:”);

scanf(“%d”,&f);

//initilizing distance and frame array

for(i=0;i<f;i++)

count[i]=0;

fr[i]=-1;

for(i=0;i<n;i++)

flag=0;

temp=pg[i];

for(j=0;j<f;j++)

if(temp==fr[j])

flag=1;
Gyan Ganga Institute of Technology and Sciences, Jabalpur

break;

if((flag==0)&&(k<f))

fault++;

fr[k]=temp;

k++;

else if((flag==0)&&(k==f))

fault++;

for(cnt=0;cnt<f;cnt++)

current=fr[cnt];

for(c=i;c>0;c–)

if(current!=pg[c])

count[cnt]++;

else

break;

}
Gyan Ganga Institute of Technology and Sciences, Jabalpur

max=0;

for(m=0;m<f;m++)

if(count[m]>max)

max=count[m];

p=m;

fr[p]=temp;

printf(“\n”);

for(x=0;x<f;x++)

printf(“%d\t”,fr[x]);

printf(“\nTotal number of faults=%d”,fault);

getchar();

OUTPUT
1)FIFO
Gyan Ganga Institute of Technology and Sciences, Jabalpur

2)OPTIMAL

3)LRU

4)Exit

Enter your choice:1

Enter size of page frame:3

0 -1 -1

0 1 -1

0 1 2

3 1 2

3 0 2

3 0 1

3 0 1

2 0 1

2 3 1

2 3 0

2 3 0

1 3 0

1 2 0

1 2 3

1 2 3

4 2 3

4 5 3

4 5 6
Gyan Ganga Institute of Technology and Sciences, Jabalpur

4 5 6

7 5 6

Page Faults=16

MENU

1)FIFO

2)OPTIMAL

3)LRU

4)Exit

Enter your choice:2

Enter frame size:3

0 -1 -1

0 1 -1

0 1 2

0 1 3

0 1 3

0 1 3

0 2 3

0 2 3

0 2 3

1 2 3

1 2 3

1 2 3

4 2 3
Gyan Ganga Institute of Technology and Sciences, Jabalpur

5 2 3

6 2 3

7 2 3

Total number of faults= MENU

1)FIFO

2)OPTIMAL

3)LRU

4)Exit

Enter your choice:3

Enter frame size:3

0 -1 -1

0 1 -1

0 1 2

3 1 2

3 0 2

1 0 2

1 0 2

1 3 2

0 3 2

1 3 2

1 3 2

1 3 2

4 3 2
Gyan Ganga Institute of Technology and Sciences, Jabalpur

4 3 5

6 3 5

6 7 5

Total number of faults=13

Practical No.8

Aim: Write a Devices Drivers for any Device or peripheral.

Purpose of a Device Driver

The purpose of a device driver is to handle requests made by the kernel with regard to a
particular type of device. There is a well-defined and consistent interface for the kernel to make
Gyan Ganga Institute of Technology and Sciences, Jabalpur

these requests. By isolating device-specific code in device drivers and by having a consistent
interface to the kernel, adding a new device is easier

Types of Device Drivers

A device driver is a software module that resides within the Digital UNIX kernel and is the
software interface to a hardware device or devices. A hardware device is a peripheral, such as a
disk controller, tape controller, or network controller device. In general, there is one device
driver for each type of hardware device. Device drivers can be classified as:

 Block device drivers


 Character device drivers (including terminal drivers)
 Network device drivers
 Pseudodevice drivers

Block Device Driver

A block device driver is a driver that performs I/O by using file system block-sized buffers from
a buffer cache supplied by the kernel. The kernel also provides for the device driver support
interfaces that copy data between the buffer cache and the address space of a process.

Block device drivers are particularly well-suited for disk drives, the most common block devices.
For block devices, all I/O occurs through the buffer cache.

Character Device Driver

A character device driver does not handle I/O through the buffer cache, so it is not tied to a
single approach for handling I/O. You can use a character device driver for a device such as a
line printer that handles one character at a time. However, character drivers are not limited to
performing I/O one character at a time (despite the name ``character'' driver). For example, tape
drivers frequently perform I/O in 10K chunks. You can also use a character device driver when it
is necessary to copy data directly to or from a user process.

Because of their flexibility in handling I/O, many drivers are character drivers. Line printers,
interactive terminals, and graphics displays are examples of devices that require character device
drivers.

A terminal device driver is actually a character device driver that handles I/O character
processing for a variety of terminal devices. Like any character device, a terminal device can
accept or supply a stream of data based on a request from a user process. It cannot be mounted as
a file system and, therefore, does not use data caching.
Gyan Ganga Institute of Technology and Sciences, Jabalpur

Network Device Driver

A network device driver attaches a network subsystem to a network interface, prepares the
network interface for operation, and governs the transmission and reception of network frames
over the network interface. This book does not discuss network device drivers.

Pseudo device Driver

Not all device drivers control physical hardware. Such device drivers are called ``pseudodevice''
drivers. Like block and character device drivers, pseudodevice drivers make use of the device
driver interfaces. Unlike block and character device drivers, pseudodevice drivers do not operate
on a bus. One example of a pseudodevice driver is the pseudoterminal or pty terminal driver,
which simulates a terminal device. The pty terminal driver is a character device driver typically
used for remote logins.

Single Binary Module

Digital UNIX provides the tools and techniques for you to produce a single binary module. A
single binary module is the executable image of a device driver that can be statically or
dynamically configured into the kernel. A single binary module has a file extension of .mod. The
.mod file for the current version of Digital UNIX is not the same as the .mod file used in
previous versions of the operating system.

When a Device Driver Is Called

Figure shows that the kernel calls a device driver during:

 Auto configuration

The kernel calls a device driver (specifically, the driver's probe interface) at auto
configuration time to determine what devices are available and to initialize them.

 I/O operations

The kernel calls a device driver to perform I/O operations on the device. These operations
include opening the device to perform reads and writes and closing the device.

 Interrupt handling

The kernel calls a device driver to handle interrupts from devices capable of generating
them.
Gyan Ganga Institute of Technology and Sciences, Jabalpur

 Special requests

The kernel calls a device driver to handle special requests through ioctl calls.

 Re-initialization

The kernel calls a device driver to reinitialize the driver, the device, or both when the bus
(the path from the CPU to the device) is reset.

 User-level requests to the sysconfig utility

The kernel calls a device driver (specifically, the driver's configure interface) to handle
requests that result from use of the sysconfig utility. The sysconfig utility allows a system
manager to dynamically configure, unconfigure, query, and reconfigure a device. These
requests cause the kernel to call the device driver's configure interface. In addition, the
driver's configure interface performs one-time initializations when called by the boot
software or by the sysconfig utility.

You might also like