39
39
Introduction:
A computer system can be divided into 4 components:
- Hardware (CPU, memory, input/output devices, etc.)
- Operating system
- System programs (word processors, spread sheets, accounting
software’s, compilers,)
- Application programs.
Lab 2
Implement CPU scheduling policies: (2-3
Lab sessions)
a) SJF
b) Priority
c) FCFS
d) Multi-level queue
Lab 3
Implement file storage allocation techniques:
a) Contiguous (using array)
b) Linked –list (using linked list)
c) Indirect allocation (indexing)
Lab 4
Implementation of Contiguous allocation techniques:
a) Worst-Fit
b) Best-Fit
c) First-Fit
Lab 5
Calculation of external and internal fragmentation.
Lab 6
External and Internal Fragmentation: Implementation of Compaction for
the continually changing memory layout and calculate total movement of
data.
Lab 7
Implementation of resource allocation graph (RAG).
Lab 8
Implementation of Banker’s Algorithm.
Lab 9
Wait Graph: Conversion of resource allocation graph (RAG) to wait-for-
graph (WFG) for each type of method used for storing graph.
Lab 10
Inter process Communication – Semaphore
a) Implement the solution for Bounded Buffer (Producer-Consumer)
problem using inter process communication technique –
Semaphores.
b) Implement the solution for Readers-Writer’s problem using inter
process communication technique – Semaphores.
c) Implement the solution for Dining-Philosopher problem using inter
process communication technique – Semaphores.
Lab 11
FORK and JOIN construct
a) Write a program where parent process take average of the odd
numbers and child process will take the average of even numbers
present in a given Aadhar number of a person. Use FORK and JOIN
construct.
b) Write a program where parent process finds additive primes and
child process finds circular prime for a given prime list array. Use
FORK and JOIN construct.
Lab:1
a) Study of hardware and software requirements of different operating
systems (UNIX, LINUX, WINDOWS XP, WINDOWS 7/8).
b) Execute various UNIX system calls for—
- Process management
- File management
- Input / Output System calls
AIM-
Studying the hardware and software requirements of various
operating systems.
Windows Requirements
The following topics provide the hardware and software requirements
for running Web Logic Integration - Business Connect on computers
with Microsoft Windows operating systems.
▪ Hardware on Windows
▪ Software on Windows
Hardware on Windows
A Windows computer must have the following minimum configuration.
▪ A Pentium-class processor running at 400 MHz or faster
Software on Windows
A Windows computer must have the following minimum
software configuration -
Operating System
WebLogic Integration - Business Connect supports the
following Windows operating systems: Windows NT 4.0 and
Windows 2000.
To use Windows NT 4.0, you also must have installed the domestic
United States version of Service Pack 4 or later with the associated
bug fixes.
Note: Apache as the mediated web server is not supported when
configured on Windows NT or Windows 2000.
In addition, you need Adobe Acrobat Reader to view and print Using
WebLogic Integration - Business Connect, which is provided in
portable document format (PDF) files. The PDFs are in the userdoc
directory on the installation CD and in the doc subdirectory after you
install the application. Acrobat Reader is available free from Adobe
Systems Inc., www.adobe.com.
UNIX Requirements
The following topics provide the hardware and software
requirements for running WebLogic Integration - Business Connect
on UNIX computers.
▪ Hardware on UNIX
▪ Software on UNIX
Hardware on UNIX
Your computer must have the following minimum configuration to
successfully install WebLogic Integration - Business Connect on a
UNIX platform.
▪ Random Access Memory (RAM)
▪ CD-ROM drive
Software on UNIX
This topic lists the operating systems and other software necessary to
install and configure WebLogic Integration - Business Connect on UNIX
platforms
X Windows and Operating Systems
Your system requires X Windows and any of the following
UNIX operating systems:
▪ Hewlett-Packard HP-UX 11.0
▪ IBM AIX 4.3.
Note. The total hard disk space required for installation can vary between
Operating system
The client is supported on workstations running:
• Red Hat® Enterprise Linux WS 3.0, updates 4-7
• Red Hat® Enterprise Linux WS 4.0, base and updates 1-3
Note. The hard disk space required for installation can vary between
300 MB and 2.6 GB (total), depending on the components selected for
installation.
Operating system
The server is supported on workstations running:
• Red Hat® Enterprise Linux WS 3.0, updates 4-7
• Red Hat® Enterprise Linux WS 4.0, base and update 1-3
Windows XP
device
• Video adapter and monitor with Super VGA (800 x 600)or higher
resolution
• Sound card
Speakers or headphones
Software Requirements
The following software is required:
• On 32-bit Windows, one of:
• Windows Vista
• Windows Server 2008
o Windows Vista
o Windows Server 2008
o Windows Server 2003
o Windows XP Professional
set classpath=jdk-install-directory\lib\tools.jar
AIM-
Execute various UNIX system calls
In computing, a system call is the programmatic way in which a
computer program requests a service from the kernel of the operating
system it is executed on. A system call is a way for programs to interact
with the operating system. A computer program makes a system call
when it makes a request to the operating system’s kernel. System
call provides the services of the operating system to the user programs
via Application Program Interface (API). It provides an interface between
a process and operating system to allow user-level processes to request
services of the operating system. System calls are the only entry points
into the kernel system. All programs needing resources must use system
calls.
Services Provided by System Calls:
1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.
Types of System Calls : There are 5 different categories of
system calls –
1. Process control: end, abort, create, terminate,
allocate and free memory.
2. File management: create, open, close, delete, read
file etc.
3. Device management
4. Information maintenance
5. Communication
Examples of Windows and Unix System Calls –
Windows Unix
CreateProcess() fork()
ExitProcess() exit()
Process Control WaitForSingleObject() wait()
CreateFile() open()
ReadFile() read()
WriteFile() write()
File Manipulation
CloseHandle() close()
SetConsoleMode() ioctl()
ReadConsole() read()
Device Manipulation WriteConsole() write()
GetCurrentProcessID() getpid()
SetTimer() alarm()
Information Maintenance Sleep() sleep()
CreatePipe() pipe()
CreateFileMapping() shmget()
Communication MapViewOfFile() mmap()
SetFileSecurity() chmod()
InitlializeSecurityDescriptor() umask()
Protection SetSecurityDescriptorGroup() chown()
3. To close a channel, use the close() system call. The prototype for
the close() system call is:
4. The read() system call does all input and the write() system call
does all output.
Lab:2
Implement CPU scheduling policies : (2-3
Lab sessions)
a) SJF
b) Priority
c) FCFS
d) Multi-level queue
STEPS TO PERFORM:
(a) For SJF algorithm, (i) We randomly generate the number of jobs. There
must be a limit on the number of jobs in a system. (ii) The execution time of
the generated jobs is also not known. Here, we are generating the CPU burst
of each job making use of the past history. (iii) All the jobs are then arranged
in a queue where searching is done to find the one with the least CPU burst.
There may be two jobs in queue with the same execution time then FCFS
approach is to be performed. Case a) If the algorithm is non preemptive in
nature, then the newly arriving job is to be added to the job queue even
though it is of lesser execution time than the one running on the processor.
Case b) Otherwise preemption is performed.
(b) For Priority scheduling, (i) We again prefer to compute the CPU burst from
past history. (ii) Priority may be assigned on the basis of their CPU burst
(simplest approach) (iii)Priority may be assigned through some random
function (within a specific range say 1 to 100). (iv) Priority has to be changed
dynamically (to perform aging in order to avoid starvation). Priority
(preemption) and priority (non preemption) nature of priority scheduling is
performed.
(c) The FCFS scheduling is performed on the basis of arrival time irrespective
of their other parameters.
(d) In multi-level queue scheduling, different queues are to be created.
OUTPUT/s: The average throughput, waiting time of process/s
DESCRIPTION
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and
the burst time Step 4: Set the waiting of the first process as ‗0‘and its
burst time as its turnaround time.
Step 5: for each process in the Ready Q calculate
Waiting time (n) = waiting time (n-1) + Burst time (n-1) b). Turnaround
time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate:
a) Average waiting time = Total waiting Time / Number of
process
b) Average Turnaround time = Total Turnaround Time / Number of
process
Step 7: Stop the process.
scanf("%d", &bt[i]);
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
OUTPUT
PROCESS BURST TIME WAITING TIME TURNAROUND
TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept
the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting
according to lowest to highest burst time.
Step 5: Set the waiting time of the first process as ‗0 and its turnaround
time as its burst time.
Step 6: Sort the processes names based
on their Burt time Step 7: For each
process in the ready queue, calculate
Waiting time(n)= waiting time (n-1) +
Burst time (n-1) Turnaround time (n)=
waiting time(n)+Burst time(n)
Step 8: Calculate
Average waiting time = Total waiting Time / Number of process
Average Turnaround time = Total Turnaround Time / Number of process.
Stop the process.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
main()
{
for(i=0;i<n;i++)
{
p[i]=i;
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i]; bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k]; p[k]=temp;
}
wt[0] = wtavg = 0;
OUTPUT tat[i]
TURN
=
BURST WAITING AROUND tat[i-
PROCESS TIME TIME TIME 1]
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
INPUT printf("\nAverage Waiting
Time -- %f", wtavg/n);
Enter the number of processes --
Enter Burst Time for Process 0 -- 6 printf("\nAverage
Enter Burst Time for Process 1 -- 8 Turnaround Time -- %f",
tatavg/n);
Enter Burst Time for Process 2 -- 7
getch();
Enter Burst Time for Process 3 -- 3
}
PRIORITY SCHEDULING:
ALGORITHM:
Step 1: Start the process
Step 3: For each process in the ready Q, assign the process id and accept
the CPU burst time
Step 5: Set the waiting of the first process as 0 and its burst time as its
turnaround time
Step 9: Calculate
Average waiting time = Total waiting Time / Number of process
Step10: Stop.
SOURCE CODE:
#include<stdio.h>
main()
{
int p[20],bt[20],pri[20],
wt[20],tat[20],i, k, n, temp; float
wtavg, tatavg;
clrscr();
printf("Enter the number of processes --- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i] = i;
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(pri[i] > pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
wtavg = wt[0] = 0;
tatavg = tat[0] = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = tat[i-1] + bt[i];
printf("\nPROCESS\t\tPRIORITY\tBURST TIME\tWAITING
TIME\tTURNAROUND TIME"); for(i=0;i<n;i++)
INPUT
Enter the number of processes
-- 5
Enter the Burst Time & Priority of
Process 0 --- 10 3
Enter the Burst Time & Priority of
Process 1---1 1
Enter the Burst Time & Priority of Process 2 --- 2 4
Enter the Burst Time & Priority of
Process 3---1 5
Enter the Burst Time & Priority of
Process 4---5 2
OUTPUT
PROCESS PRIORITY BURST TIME WAITIN G TURNARO
TIME 0 -UND TIME
1 1 1 1 1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19
SOURCE CODE
main(){
for(i=0;i<n;i++)
{
p[i] = i;
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(su[i] > su[k])
{
temp=p[i]; p[i]=p[k]; p[k]=temp;
temp=bt[i]; bt[i]=bt[k]; bt[k]=temp;
temp=su[i]; su[i]=su[k]; su[k]=temp;
wtavg = wt[0] = 0;
tatavg = tat[0] = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = tat[i-1] + bt[i];
for(i=0;i<n;i++)
{
printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ",p[i],su[i],bt[i],wt[i],tat[i]);
Lab:3
Implement file storage allocation techniques:
a) Contiguous (using array)
b) Linked –list (using linked list)
c) Indirect allocation (indexing)
IMPLEMENTATION DETAILS: INPUT/s :
(i) Free storage blocks to allocate storage to files.
STEPS TO PERFORM: Before performing storage allocation, we need to
perform the following common steps:
(i) During program execution, we need an illusion that we have a large
disk space for allocation strategies.
(ii) We take a big array of structure (representing storage space in terms
of sectors). This space is equal to the disk size available for storage.
(iii) Next step is to see free space list. The free space list is not entirely
free. Some portion of this list is occupied by some OS or user files/data.
(iv) The free-space is to be maintained in a suitable manner as per
allocation strategy.
(v) Upon the above formed disk space and free space list, we then
implement the above mentioned techniques.
(vi) Symbolic file name and size will be inputted by the user and
accordingly the assumed disk space as well as free space list will be
updated.
DESCRIPTION:
ALGORITHM:
Step 1: Start the program.
SOURCE CODE:
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1
;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1) goto X;
else exit();
getch();
OUTPUT:
Enter the starting block
INDEXED ALLOCATION
AIM:
To implement allocation method using chained method
DESCRIPTION:
In the chained method file allocation table contains a field which
points to starting block of memory. From it for each bloc a pointer
is kept to next successive block. Hence, there is no external
fragmentation.
ALGORITHM:
Step 1: Start the program.
q=random(100);
{
if(b[q].flag==0)
b[q].flag=1;
b[q].fno=j;
r[i][j]=q;
for(i=0;i<50;i++)
f[i]=0;
printf("enter index block\t");
scanf("%d",&p);
if(f[p]==0)
{
f[p]=1;
printf("enter no of files on index\t");
scanf("%d",&n);
}
else
{
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
{
}
for(j=0;j<n;j++) f[inde[j]]=1;
printf("\n allocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
scanf("%d",&c);
if(c==1) goto x;
else exit();
getch();
OUTPUT:
enter index block 9
LINKED:
AIM:
To implement linked file allocation technique.
DESCRIPTION:
In the chained method file allocation table contains a field which
points to starting block of memory. From it for each bloc a pointer
is kept to next successive block. Hence, there is no external
fragmentation
ALGORTHIM:
for(i=0;i<n;i++)
{
for(j=0;j<s[i];j++)
{
q=random(100);
if(b[q].flag==0)b[q].
flag=1; b[q].fno=j;
r[i][j]=q;
if(j>0)
{
}
}
p=r[i][j-1]; b[p].next=q;}
Step 5: Print the results file no, length ,Blocks allocated.
Step 6: Stop the program
SOURCE CODE:
#include<stdio.h>
main()
{
int f[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enter the starting index block & length");
scanf("%d%d",&st,&len);
k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{ f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
getch( );}
OUTPUT
Enter how many blocks that are already allocated 3 Enter the blocks
no.s that are already allocated 4 7 Enter the starting index block &
length 3 7 9
3->1
6->1
11->1
12->1
Lab: 4
AIM:
Implementation of Contiguous allocation techniques:
a) Worst-Fit
b) Best-Fit
c) First-Fit
STEPS TO PERFORM:
(i) We consider the same free space list and files/processes as created in
experiment 3 for our system.
(ii) Implement the above mentioned three contiguous allocation
techniques. Also, the free space list is updated from the free blocks left
out after performing allocation.
DESCRIPTION
One of the simplest methods for memory allocation is to divide
memory into several fixed-sized partitions. Each partition may contain
exactly one process. In this multiple-partition method, when a
partition is free, a process is selected from the input queue and is
loaded into the free partition. When the process terminates, the
partition becomes available for another process. The operating
system keeps a table indicating which parts of memory are available
and which are occupied. Finally, when a process arrives and needs
memory, a memory section large enough for this process is provided.
When it is time to load or swap a process into main memory, and if
there is more than one free block of memory of sufficient size, then
the operating system must decide which free block to allocate. Best-
fit strategy chooses the block that is closest in size to the request.
First-fit chooses the first available block that is large enough. Worst-fit
chooses the largest available block.
SOURCE CODES
WORST-FIT:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,t emp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme
-First Fit"); printf("\nEnter the number of
blocks:"); scanf("%d",&nb);
scanf("%d",&nf);
printf("\nEnter thesize of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size Of the files:-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j; break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
INPUT:
Enter the number of blocks: 3
Enter the number of files: 2
Enter the size of the blocks:-
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 1 5 4
2 4 3 7 3
BEST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i]; if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}}
frag[i]=lowest; bf[ff[i]]=1;
lowest=10000;
printf("\nFileNo\tFileSize\tBlockNo\tBlock
Size\tFragment"); for(i=1;i<=nf && ff[i]!
=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 2: 4
OUTPUT
1 1 2 2 1
2 4 1 5 1
FIRST-FIT
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
printf("\n\tMemory Management
Scheme - Worst Fit"); printf("\nEnter the
number of blocks:"); scanf("%d",&nb);
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n"); for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
}
}
frag[i]=highest; bf[ff[i]]=1;
highest=0;
}
ff[i]=j;
highest=temp;
}
printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 3 7 6
2 4 1 5 1
Lab: 5
AIM
Calculation of external and internal fragmentation.
DESCRIPTION
IMPLEMENTATION DETAILS: INPUT/s:
(i) Free space list of blocks from system (as in experiment 3).
(ii) List processes and files from the system (as in experiment 3).
STEPS TO PERFORM:
(i) Completing experiment 4, we end up getting list of allotted files,
remaining part of allotted block and blocks which cannot be allotted
(ii) After implementing each allocation algorithm, list the amount of free
space blocks left out after performing allocation.
(iii) When a block which is not at all allocated to any process or file, it adds
to external fragmentation.
(iv) When a file or process is allocated the free block and still some part of
it is left unused, we count such unused portion into internal
fragmentation. OUTPUT/s: Processes and files allocated to free blocks.
From the list of unused blocks, we determine the count of total internal
and external fragmentation.
Internal Fragmentation
When a process is assigned to a memory block and if that process is
smaller than the memory requested, it creates a free space in the
assigned memory block. Then the difference between assigned and
requested memory is called the internal fragmentation.
External Fragmentation
When the process is loaded or removed from the memory, a free space is
created. This free space creates an empty space in the memory which is
called external fragmentation.
Definition When there is a difference When there are small and non-
between required memory contiguous memory blocks
space vs allotted memory which cannot be assigned to
space, problem is termed as any process, the problem is
Internal Fragmentation. termed as External
Fragmentation.
Solution Best Fit Block Search is the Compaction is the solution for
solution for internal external fragmentation.
fragmentation.
Lab:6
AIM:
Implementation of Compaction for the continually changing memory layout and
calculate total movement of data.
ASSUMPTION:
the files must be inserted and deleted continuously.
DESCRIPTION:
External and Internal Fragmentation: Implementation of Compaction for
the continually changing memory layout and calculate total movement of
data. the dynamic partitioning suffers from external fragmentation.
However, this can cause some serious problems.
To avoid compaction, we need to change the rule which says that the
process can't be stored in the different places in the memory.
As shown in the image above, the process P5, which could not be loaded
into the memory due to the lack of contiguous space, can be loaded now
in the memory since the free partitions are made contiguous.
Huge amount of time is invested for this procedure and the CPU will
remain idle for all this time. Despite of the fact that the compaction avoids
external fragmentation, it makes system inefficient.
1. 1 B transfer needs 6 NS
2. 256 MB transfer needs 256 X 2^20 X 6 X 10 ^ -9 secs
hence, it is proved to some extent that the larger size memory transfer
needs some huge amount of time that is in seconds.
Lab:7
AIM
Implementation of resource allocation graph (RAG).
IMPLEMENTATION DETAILS:
INPUT/s:
(i) List of resources
(ii) Instance of each resource (for case 2 only)
(iii) List of processes
(iv) Resource allocated by each process
STEPS TO PERFORM:
(i) List the processes and resources.
(ii) We read input from user for each [Pi , Ri] and also how many instances
of each resource to a particular process (for multiple instances case).
(iii) While user completes the input, we end up constructing adjacency
matrices/ list. Two cases to be considered:
OUTPUT/s:
Output is a Resource allocation graph through matrices/list.
DESCRIPTION
We know that any graph contains vertices and edges. So RAG also
contains vertices and edges. In RAG vertices are two type –
Now coming to the edges of RAG.There are two types of edges in RAG –
If there is a cycle in the Resource Allocation Graph and each resource in the
cycle provides only one instance, then the processes will be in deadlock.
For example, if process P1 holds
From the above example, it is not possible to say the RAG is in a safe
state or in an unsafe state. Thus, to see the state of this RAG, let’s
construct the allocation matrix and request matrix.
• The total number of processes are three; P1, P2 & P3 and the
total number of
resources are two; R1 & R2.
Allocation matrix –
Request matrix –
So, there is no deadlock in this RAG. Even though there is a cycle, still
there is no deadlock. Therefore in multi-instance resource cycle is not
sufficient condition for deadlock.
So, the Available resource is = (0, 0), but requirement are (0, 1), (1,
0) and (1, 0). So, you can’t fulfil any one requirement. Therefore, it
is in deadlock.
LAB:8
AIM
DESCRIPTION
SAFETY ALGORITHM
ALGORITHM:
11. End
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int alloc[10][10],max[10][10];
int avail[10],work[10],total[10];
int i,j,k,n,need[10][10];
int
m;
int count=0,c
=0;
char finish[10];
clrscr();
printf("Ente processe resource
r the no. of s and s:");
scanf("%d
%d",&n,&m);
for(i=0;i<=n;i+
+)
finish[i]='n
';
printf("Ente clai
r the m matrix:\n");
for(i=0;i<n;
i++)
for(j=0;j<m;j++)
scanf("%d",&max
[i][j]);
printf("Ente matrix:\n"); for(i=0;i<n;i+
r the allocation +)
for(j=0;j<m;j++)
scanf("%d",&alloc[i][j]); printf("Resource vector:");
for(i=0;i<m;i++)
scanf("%d",&total[i]);
for(i=0;i<m;i++)
avail[i]=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
avail[j]+=alloc[i][j];
work[i]=avail[i]; for(j=0;j<m;j++)
work[j]=total[j]-work[j];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
need[i][j]=max[i][j]-alloc[i][j];
A:
for(i=0;i<n;i++)
{
c=0;
for(j=0;j<m;j++)
if((need[i][j]<=work[j])&&(finish[i]=='n'))
c++;
if(c==m)
{
OUTPUT
Enter the no. of processes and resources: 4 3 Enter the claim matrix:
322
613
314
422
Enter the allocation matrix:
100
612
211
002
Resource vector:9 3 6
LAB: 9
AIM
DESCRIPTION
1.
P1
P2
LAB: 10
AIM
To Write a C program to simulate producer-consumer problem using
semaphores.
DESCRIPTION
PROGRAM
#include<stdio.>
void main()
{
out = 0;
bufsize =
10;
while(choice !=3)
{
Exit”
printf(“\n1. Produce \t 2. Consume \t3. );
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;
}
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; }
}
OUTPUT
1. Produce
Consume 2.
Exit Enter your
3. choice: 2
Buffer is
Empty
1. Produce 2.
Exit Enter your
Consume 3. choice: 1
Enter the
value: 100
1. Produce 2.
Exit Enter your
Consume 3. choice: 2
The consumed value
is 100
1. Produce 2.
Exit Enter your
Consume 3. choice: 3
DESCRIPTION
chopsticks. When a philosopher thinks, she does not interact with her
colleagues. From time to time, a philosopher gets hungry and tries to
pick up the two chopsticks that are closest to her (the chopsticks that
are between her and her left and right neighbors). A philosopher may
pick up only one chopstick at a time. Obviously, she cam1ot pick up a
chopstick that is already in the hand of a neighbor. When a hungry
philosopher has both her chopsticks at the same time, she eats without
releasing her chopsticks. When she is finished eating, she puts down
both of her chopsticks and starts thinking again. The dining-
philosophers problem may lead to a deadlock situation and hence some
rules have to be framed to avoid the occurrence of deadlock.
PROGRAM
int tph, philname[20], status[20],
howhung, hu[20], cho; main()
{
int i; clrscr();
printf("\n\nDINING PHILOSOPHER
PROBLEM"); printf("\nEnter the total
no. of philosophers: ");
scanf("%d",&tph);
for(i=0;i<tph;i++)
{
philname[i]=(i+1);
status[i]=1;
}
printf("How many are hungry : ");
scanf("%d", &howhung); if(howhung==tph)
{
for(i=0;i<howhung;i++)
{
printf(“Enterphilosopher%dposition:”,(i+1));
scanf(“%d”,&hu[i]);
status[hu[i]]=2;
}
do
{
switch(cho)
{
case 1:
one();
break;;;
CASE 2
two();
break; case 3: exit(0);
default: printf("\nInvalid option..");
}
}
one()
{
}
}while(1);
int pos=0, x, i;
}
two()
{
int i, j, s=0, t, r, x;
if(abs(hu[i]-hu[j])>=1&& abs(hu[i]-hu[j])!=4)
{
printf("\n\ncombination %d \n", (s+1));
t=hu[i];
r=hu[j]; s++;
if((hu[x]!=t)&&(hu[x]!=r))
printf("\nP %d is waiting", philname[hu[x]]);
}
}}}}
Lab: 11
AIM
Write a program where parent process takes average of the odd numbers
and child process will take the average of even numbers present in a
given Aadhar number of a person. Use FORK and JOIN construct.
DESCRIPTION
System call fork() is used to create processes. The purpose of fork() is to
create a new process, which becomes the child process of the caller. After
a new child process is created, both processes will execute the next
instruction following the fork() system call.
as system calls. The fork() call creates a new child process which runs
concurrently with the parent. The child process is an exact copy of the
parent except that it has a new process id.
The join() is called by both the parent and the child. The child
process calls join() after it has finished execution. This operation is
done implicitly. The parent process waits until the child joins and
continues later.
There are two join scenarios:
1. The child joins first and then the parent joins without waiting
for any process.
2. The parent process joins first and wait, the child process joins,
and the parent continues thereafte.
SOURCE CODE:
#include <unistd.h>
using namespace std;
/
Driv
er
cod
e
int
mai
n()
{
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sumOdd = 0, sumEven = 0,
SEA, SOA, n, i; n = fork();
/ Checking if n is
not 0 if (n > 0) {
for (i = 0; i < 10;
i++) { if
(a[i] % 2 ==
0)
sumEven = sumEven + a[i]
}
SEA = sumEven/i;
cout << "Parent process \n";
cout << "Sum of even numbers in adhar number is "
<< sumEven << endl; cout<< "The average of sum of even
numbers is:"<< SEA << endl;
}
/ If n is 0 i.e. we are in child
process else {
for (i = 0; i < 10;
i++) { if
(a[i] % 2 !=
0)
sumOdd = sumOdd + a[i];
}
SOA = sumOdd/n;
cout << "Child process \n";
cout << "\nSum of odd number in adhar number is "
<< sumOdd << endl; cout<<"\n average of sum of odd
numbers is"<< SOA <<endl;
}
return 0;
}
OUTPUT
Parent process
Sum of even numbers in adhar number is 30
The average of sum of even numbers is:6
Child process
Sum of even numbers in the adhar number is 25
The average of sum of add numbers is: 5
AIM
Write a program where parent process finds additive primes and child
process finds circular prime for a given prime list array, using fork and
Join.
Source code
/ Program to check
if a number is circular //
prime or not.
#include
<iostream>
#include
<cmath>
using
namespace
std;
/ Function to check if a
number is prime or not. bool
isPrime(int n)
{
/ Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
return true;
}