2302IT451 OS lab manual
2302IT451 OS lab manual
Regulation 2023
Prepared By
Assistant Professor/IT
Vision of the Department
To produce globally competent information technologist and to inculcate values of leadership and
research qualities in them
To provide high quality Education to the students by our competent faculty members,
effective teaching learning process and value added courses
To create centres of excellence by interacting with industries for better employability and to
contribute to the society through consultancy and R&D works.
To improve the soft skill, interpersonal skill, ethical behavior and communication skill of
students by involving them in team works and technical events
● PEO1: Graduates will have knowledge and competency for successful careers in and related
to Information Technology
● PEO2: Graduates will contribute to the design and implementation of software systems to
solve real life problems in the society with an understanding of profession ethical standards
● PEO3: Graduates will proceed to higher studies in Engineering or other Professional fields and
promote awareness of the life-long learning
● PEO4: Graduates will work and communicate effectively as individuals and as team members
in multidisciplinary projects, research and development activities
0031
List of Experiments:
COURSE OUTCOMES:
after completion of the course, Student will be able to
CO1: Demonstrate proficiency in using essential UNIX commands
CO2: Utilize system calls effectively for process creation, process management, inter-process communication,
file system operations, and I/O operations.
CO3: Write shell scripts for automating tasks, managing processes, and interacting with the operating system
CO4: Implement and analyze CPU scheduling algorithms and synchronization mechanisms
Co5: Implement and analyze deadlock handling techniques, file allocation methods and memory management
techniques
SCHEME OF ASSESSMENT Courses offered under B.E. / B.Tech. Programmes are assessed as given below:
LABORATORY COURSES
Continuous Assessment 60
Distribution of marks for Continuous Assessment:
Conduct of Experiment (45)
i. Preparation (10)
ii. ii. Experiment and Results (20)
iii. iii. Record / Observation (15)
Test – Cycle I (7.5)
Test – Cycle II (7.5)
End Semester Examination 40
Experiments & Results (30)
Quiz comprising all experiments – (10)
Total Marks 100
1.1 OVERVIEW
An Operating System (OS)(as shown in Fig 1) is an interface between a computer user and computer
hardware. An operating system is a software which performs all the basic tasks like file management, memory
management, process management, handling input and output, and controlling peripheral devices such as
disk drives and printers.
Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS,
OS/400, AIX, z/OS, etc. Following are some of important functions of an operating System:
Memory Management
Processor Management
Device Management
File Management
Security
Control over system performance
Job accounting
Error detecting aids
Coordination between other software and end users.
Support code which is not required to run in kernel mode is in System Library. User programs and
other system programs works in User Mode which has no access to system hardware and kernel code. User
programs/ utilities use System libraries to access Kernel functions to get system's low level tasks.
AIM
To study and implement about the various basic linux commands.
RESULT
Thus the linux commands have been studied and executed successfully.
SYSTEM CALLS
It is an interface between process and kernel
It is way for programs to interact with OS
Five different types of system calls are available. They are
1. Process Control
2. File Management
3. Device Management
4. Information Management
5. Communication
Examples
fork()
It is an important system calls which is used to create a new process in the OS
The newly created process is called as child process and caller of the child process is called as
parent process
It takes no arguments and returns the process ID
It is called once but returns twice (once in parent and once in the child)
The new process gets a copy of the current program, but new process id (pid). The process id
of the parent process (the process that called fork()) is registered as the new processes parent
pid (ppid) to build a process tree.
It is an important to note that, Unix / Linux will make an exact copy of the parent's address
space and give it to the child. Therefore, the parent and child processes have separate
address spaces.
It returns the following values:
o Negative - new process creation was unsuccessful
o Zero - returned to child process
o Positive - returned to parent (caller) process
Child Process
The newly created process is called as child process
It is identified by the return code is 0
Parent Process
Formula
Total number of processes (T) : 2n
Total number of Child processes (C) : 2n-1
Total number of Child processes (P) : T-C
NOTE
After the fork(), both parent and child processes are running simultaneously
The newly created process is called as child process which is identified by the return code is 0
and the caller of the child process is called as parent process which is identified by positive
value (>0)
Program statements before fork() is common for both child and parent processes but after
fork() call, the rest of the program instructions will be allocated separately for child and
parent process
Child and parent processes don’t share common address space. They are having own memory
address space. So if there are any changes in child process won’t reflect the parent process.
Similarly, if there are any changes in parent processes won’t reflect the child process.
TOOLS SUPPORT
Compiler : gcc compiler (gcc <filename>.c)
Execution : ./a.out (assembly output)
OS : Linux OS platform
When the child process is created, both the parent process and the child process will point to
the next instruction (same Program Counter) after the fork().
In this way the remaining instructions or C statements will be executed the total number of
process times, that is 2n times, where n is the number of fork() system calls
1. getpid()
It is a built-in function and available in #include<unistd.h> header file
It is used to return the process ID of child process (newly created process)
Return value: pid_t
pid_t
It stands for process id type and built-in variable to store the process ids of parent and child
function
It is the type of the process ID which returns an unsigned integer value.
It is available in #include<sys/types.h>
NOTABLE POINTS
wait(NULL) will block the parent process until any of its children has finished their execution
(parent process will be blocked until child process returns an exit status to the operating
system which is then returned to parent process)
If child finishes before parent reaches wait(NULL) then it will read the exit status, release the
process entry in the process table and continue execution until it finishes as well.
Wait can be used to make the parent process wait for the child to terminate (finish) but not
the other way around
Wait(NULL) simply making the parent wait for the child.
On success, wait() returns the process ID of terminated child process while on failure it
returns -1
Once child process finishes, parent resumes and prints the rest of the statements of parent
process
exit()
It is system call and available in #include<stdlib> file
It takes only one parameter which is exit status as a parameter
It is used to close all files, sockets, frees all memory and then terminates the process.
Syntax of create() in C
int create(char *filename, mode_t mode);
Parameter
filename: name of the file which you want to create
mode: indicates permissions of the new file.
Return Value
return first unused file descriptor (generally 3 when first creating use in the process because
0, 1, 2 fd are reserved)
return -1 when an error
2. C open
The open() function in C is used to open the file for reading, writing, or both.
It is also capable of creating the file if it does not exist. It is defined
inside <unistd.h> header file and the flags that are passed as arguments are defined
inside <fcntl.h> header file.
Syntax of open() in C
int open (const char* Path, int flags);
Parameters
Path: Path to the file which we want to open.
Use the absolute path beginning with “/” when you are not working in the same
directory as the C source file.
Use relative path which is only the file name with extension, when you are working
in the same directory as the C source file.
flags: It is used to specify how you want to open the file. We can use the following flags.
Syntax of close() in C
int close(int fd);
Parameter
fd: File descriptor of the file that you want to close.
Return Value
0 on success.
-1 on error.
Output
opened the fd = 3
closed the fd.
Syntax of read() in C
size_t read (int fd, void* buf, size_t cnt);
Parameters
fd: file descriptor of the file from which data is to be read.
buf: buffer to read data from
cnt: length of the buffer
Return Value
return Number of bytes read on success
return 0 on reaching the end of file
return -1 on error
return -1 on signal interrupt
Important Points
buf needs to point to a valid memory location with a length not smaller than the specified size
because of overflow.
fd should be a valid file descriptor returned from open() to perform the read operation
because if fd is NULL then the read should generate an error.
cnt is the requested number of bytes read, while the return value is the actual number of
bytes read. Also, some times read system call should read fewer bytes than cnt.
int main()
{
char c;
int fd1 = open("sample.txt", O_RDONLY, 0);
int fd2 = open("sample.txt", O_RDONLY, 0);
read(fd1, &c, 1);
read(fd2, &c, 1);
printf("c = %c\n", c);
exit(0);
}
Output
c=f
Syntax of write() in C
size_t write (int fd, void* buf, size_t cnt);
Parameters
fd: file descriptor
buf: buffer to write data from.
cnt: length of the buffer.
Return Value
returns the number of bytes written on success.
return 0 on reaching the End of File.
return -1 on error.
return -1 on signal interrupts.
close(fd[0]);
close(fd[1]);
return 0;
}
Output
hello world
SELECTION STATEMENTS
1. Simple If statement
2. If else Statement
3. If else if Statement
4. Case Statement
1. Simple If Statement
Syntax
2. If else Statement
Syntax
3. If…elif…else Statement
It is an important to note that, the simple if, if else and if-elif-else should be closed by fi keyword.
Syntax
4. Case Statement
It is equivalent to switch case statements in c language
It is used to execute several statements based on the value of expression
This is done by using the reserved word case
It is an alternative option for if..elif..else statements
LOOPING STATEMENTS
1. While loop (while)
2. Until loop (until)
3. For loop (for)
1. While loop
Syntax
SOURCE CODE
while :
do
echo "Hello World"
done
(OR)
while true
do
echo "Hello World"
OUTPUT:
OUTPUT
3. For loop
Syntax
Where,
Variable can be any user defined name
w1 w2 …wn - list of the values separated by spaces
AIM:
To write a ‘C’ program to implement FCFS Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating FCFS scheme.
Step 2: Declare the variables to calculate the essential aspects of FCFS.
Step 3: Initially get the process time and burst time.
Step 4: Swap all the processes in such a way that they are arranged in FCFS order.
Step 5: Prepare the gantt chart for each process so that their waiting time, turn_around time is calculated.
Step 6: Calculate the average waiting time and average turn_around time and display the result.
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,k,n,p[10],bur[10],wat[10],tur[10],ttur=0,twat=0,t;
float awat,atur;
printf("\nEnter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the burst time for process %d: ",(i+1));
scanf("%d",&bur[i]);
p[i]=i+1;
}
printf("\nPROCESS \t BURST TIME \t WAITING TIME \t TURN AROUND TIME\n");
wat[0]=0;
for(i=0;i<n;i++)
{
wat[i+1]=wat[i]+bur[i];
tur[i]=wat[i]+bur[i];
}
for(i=0;i<n;i++)
{
ttur=ttur+tur[i];
twat=twat+wat[i];
}
for(i=0;i<n;i++)
{ printf("\n%d\t\t%d\t\t%d\t\t%d\n",p[i],bur[i],wat[i],tur[i]);
}
printf("\nGAANT CHART\n\n");
for(i=0;i<n;i++)
{ printf("--------");
}
OUTPUT:
[smk @cseserver3]$ cc prg1.c
[smk @cseserver3]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 10
Enter the burst time for process 2: 5
Enter the burst time for process 3: 8
AIM:
To write a ‘C’ program to implement SJF Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating SJF scheme.
Step 2: Declare the variables to calculate the essential aspects of SJF.
Step 3: Initially get the process time and burst time.
Step 4: Swap all the processes in such a way that they are arranged in shortest job first (SJF) order.
Step 5: Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
Step 6: Calculate the average waiting time and average turn around time and display the result.
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,k,n,p[10],bur[10],wat[10],tur[10],ttur=0,twat=0,t;
float awat,atur;
printf("\nEnter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the burst time for process %d: ",(i+1));
scanf("%d",&bur[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(bur[i]>bur[j])
{
t=bur[i];
bur[i]=bur[j];
bur[j]=t;
t=p[i];
p[i]=p[j];
p[j]=t;
}
}
}
printf("\nPROCESS\tBURST TIME \t WAITING TIME \t TURN AROUND TIME\n");
wat[0]=0;
for(i=0;i<n;i++)
{
AIM:
To write a ‘C’ program to implement PRIORITY Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating priority scheme.
Step 2: Declare the variables to calculate the essential aspects of priority scheme.
Step 3: Initially get the process time, arrival time and burst time along with their priorities.
Step 4: Execute the process by referring to their priority values.
Step 5: Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
Step 6: Calculate the average waiting time and average turn around time and display the result.
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,k,n,p[10],pri[10],bur[10],wat[10], tur[10],ttur=0,twat=0,t;
float awat,atur;
printf("\nEnter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the burst time for process %d: ",(i+1));
scanf("%d",&bur[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
printf("\nEnter the priority for process %d: ",(i+1));
scanf("%d",&pri[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(pri[i]>pri[j])
{
t=bur[i];
bur[i]=bur[j];
bur[j]=t;
t=p[i];
p[i]=p[j];
p[j]=t;
t=pri[i];
pri[i]=pri[j];
RESULT:
Thus the program for priority scheduling is successfully implemented.
PROGRAM:
#include<stdio.h>
void main()
{
int i,x=-1,k[10],m=0,n,t,s=0;
int a[50],temp,b[50],p[10],bur[10],bur1[10];
int wat[10],tur[10],ttur=0,twat=0,j=0;
float awat,atur;
printf("Enter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the burst time for process %d: ",(i+1));
scanf("%d",&bur[i]);
bur1[i]=bur[i];
}
printf("\nEnter the slicing time :");
scanf("%d",&t);
for(i=0;i<n;i++)
{
b[i]=bur[i]/t;
if((bur[i]%t)!=0)
b[i]=b[i]+1;
m=b[i]+m;
}
printf("\nGAANT CHART\n\n");
for(i=0;i<m;i++)
{
printf("--------");
}
printf("\n");
a[0]=0;
DESCRIPTION:
Producer-consumer problem, is a common paradigm for cooperating processes. A producer process produces
information that is consumed by a consumer process. One solution to the producer-consumer problem uses
shared memory. To allow producer and consumer processes to run concurrently, there must be available a
buffer of items that can be filled by the producer and emptied by the consumer. This buffer will reside in a
region of memory that is shared by the producer and consumer processes. A producer can produce one item
while the consumer is consuming another item. The producer and consumer must be synchronized, so that
the consumer does not try to consume an item that has not yet been produced.
ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the critical section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable to the buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove item from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result
PROGRAM:
#define BUFFERSIZE 10
int mutex,n,empty,full=0,item,item1;
int buffer[20];
int in=0,out=0,mutex=1;
void wait(int s)
{ while(s<0)
{
printf(“\nCannot add an item\n”);
exit(0);
} s--;
}
void signal(int s)
{ s++;
}
void producer()
{
do {
wait (empty);
wait(mutex);
DESCRIPTION:
In a multiprogramming environment, several processes may compete for a finite number of resources. A
process requests resources; if the resources are not available at that time, the process enters a waiting state.
Sometimes, a waiting process is never again able to change state, because the resources it has requested are
held by other waiting processes. This situation is called a deadlock. Deadlock avoidance is one of the
techniques for handling deadlocks. This approach requires that the operating system be given in advance
additional information concerning which resources a process will request and use during its lifetime. With this
additional knowledge, it can decide for each request whether or not the process should wait. To decide
whether the current request can be satisfied or must be delayed, the system must consider the resources
currently available, the resources currently allocated to each process, and the future requests and releases of
each process. Banker’s algorithm is a deadlock avoidance algorithm that is applicable to a system with multiple
instances of each resource type
ALGORITHM:
Banker's Algorithm follows two algorithms.
Safety algorithm - This algorithm checks if a system is in a safe state.
Resource-Request Algorithm - This algorithm performs actions based on requests.
Safety Algorithm
1) Let us assume Work and Finish be vectors of size ‘m’ and ‘n’.
Initialize: Work = Available
Finish[i] = false; for i=1, 2,...n
Resource-Request Algorithm
PROGRAM
#include <stdio.h>
#include <conio.h>
void main() {
int k=0,a=0,b=0,instance[5],availability[5],allocated[10][5],need[10][5],MAX[10][5],
int process,P[10],no_of_resources, cnt=0,i, j;
printf("\n Enter the number of resources : ");
scanf("%d", &no_of_resources);
printf("\n enter the max instances of each resources\n");
for (i=0;i<no_of_resources;i++) {
availability[i]=0;
printf("%c= ",(i+97));
scanf("%d",&instance[i]);
}
printf("\n Enter the number of processes : ");
scanf("%d", &process);
printf("\n Enter the allocation matrix \n ");
for (i=0;i<no_of_resources;i++)
printf(" %c",(i+97));
printf("\n");
for (i=0;i <process;i++) {
P[i]=i;
printf("P[%d] ",P[i]);
for (j=0;j<no_of_resources;j++) {
scanf("%d",&allocated[i][j]);
availability[j]+=allocated[i][j];
}
}
printf("\nEnter the MAX matrix \n ");
for (i=0;i<no_of_resources;i++) {
printf(" %c",(i+97));
availability[i]=instance[i]-availability[i];
}
printf("\n");
OUTPUT
Enter the number of resources: 3
RESULT:
Thus the program for solving Bankers algorithm for deadlock avoidance was executed successfully.
AIM:
To write a program to develop application using inter process communication.
ALGORITHM:
Step1: Start the process.
Step2: Enter the limit for Fibonacci series in the parent process.
Step3: Display the series in child process.
Step4: Stop the process.
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/io.h>
#include<sys/types.h>
Void main()
{
int pid,pfd[2],n,a,b,c;
if(pipe (pfd)== -1)
{
printf(“\n error in the pipe connection\n”);
exit(1);
}
pid=fork();
if(pid>0)
{
printf(“\n parent process”);
printf(“\n Fibonacci series\n”);
printf(“\n enter the limit for the series:”);
scanf(“%d”, &n);
close(pfd[0]);
write(pfd[1], &n, sizeof(n));
close(pfd[1]);
exit(0);
}
else
{
close(pfd[1]);
read(pfd[0], &n , sizeof(n));
printf(“child process”);
a=0;
b=1;
close(pfd[0]);
printf(“\n fibonacci series”);
printf(“\n\n %d \n %d”,a,b);
RESULT:
Thus the program to implement interprocess communication is executed.
AIM:
Write a C Program to implement Sequential File Allocation method.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the number of memory partition and their sizes.
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches all the entire memory block until a hole which is big enough is
encountered. It allocates that memory block for the requesting process.
Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can be allocated to
requesting process and allocates if.
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and allocates it to the process.
Step 7: Analyses all the three memory management techniques and display the best algorithm which utilizes
the memory resources effectively and efficiently.
Step 8: Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
clrscr();
printf("Enter no.of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter no. of blocks occupied by file%d",i+1);
scanf("%d",&b[i]);
printf("Enter the starting block of file%d",i+1);
scanf("%d",&sb[i]);
t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
}
printf("Filename\tStart block\tlength\n");
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
printf("Enter file name:");
scanf("%d",&x);
printf("File name is:%d",x);
printf("length is:%d",b[x-1]);
printf("blocks occupied:");
OUTPUT:
Enter no.of files: 2
Enter no. of blocks occupied by file1 4
Enter the starting block of file1 2
Enter no. of blocks occupied by file2 10
Enter the starting block of file2 5
Filename Start block length
1 2 4
2 5 10
Enter file name: Ram
RESULT:
Thus the program to implement sequential file allocation is executed successfully.
AIM:
Write a C Program to implement Indexed File Allocation method.
Algorithm:
Step 1: Start.
Step 2: Let n be the size of the buffer
Step 3: check if there are any producer
Step 4: if yes check whether the buffer is full
Step 5: If no the producer item is stored in the buffer
Step 6: If the buffer is full the producer has to wait
Step 7: Check there is any cosumer.If yes check whether the buffer is empty
Step 8: If no the consumer consumes them from the buffer
Step 9: If the buffer is empty, the consumer has to wait.
Step 10: Repeat checking for the producer and consumer till required
Step 11: Terminate the process.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
clrscr();
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter starting block and size of file%d:",i+1);
scanf("%d%d",&sb[i],&s[i]);
printf("Enter blocks occupied by file%d:",i+1);
scanf("%d",&m[i]);
printf("enter blocks of file%d:",i+1);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
}
printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
}
printf("\nEnter file name:");
scanf("%d",&x);
printf("file name is:%d\n",x);
i=x-1;
printf("Index is:%d",sb[i]);
2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 51
printf("Block occupied are:");
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
getch();
}
OUTPUT:
Enter no. of files:2
Enter starting block and size of file1: 2 5
Enter blocks occupied by file1:10
enter blocks of file1:3
2 5 4 6 7 2 6 4 7
Enter starting block and size of file2: 3 4
Enter blocks occupied by file2:5
enter blocks of file2: 2 3 4 5 6
File index length
1 2 10
2 3 5
Enter file name: venkat
file name is:12803
Index is:0Block occupied are:
RESULT:
Thus the program to implement indexed file allocation is executed successfully.
AIM:
Write a C Program to implement Linked File Allocation method.
ALGORITHM:
Step 1: Create a queue to hold all pages in memory
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 4: Create a stack
Step 5: When the page fault occurs replace page present at the bottom of the stack
Step 6: Stop the allocation.
Program:
#include<stdio.h>
#include<conio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
main()
{
int i,j,n;
clrscr();
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&f[i].fname);
printf("Enter starting block:");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("Enter no.of blocks:");
scanf("%d",&f[i].size);
printf("Enter block numbers:");
for(j=1;j<=f[i].size;j++)
{
scanf("%d",&f[i].block[j]);
}
}
printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
OUTPUT:
Enter no. of files:2
Enter file name:venkat
Enter starting block:20
Enter no.of blocks:6
Enter block numbers: 4
12
15
45
32
25
Enter file name:rajesh
Enter starting block:12
Enter no.of blocks:5
Enter block numbers:6
5
4
3
2
File start size block
venkat 20 6 4--->12--->15--->45--->32--->25
rajesh 12 5 6--->5--->4--->3--->2
RESULT:
Thus the program to implement linked file allocation is executed successfully.
AIM:
To write UNIX C program a program to implement LRU page replacement algorithm.
DESCRIPTION:
The Least Recently Used replacement policy chooses to replace the page which has not been referenced
for the longest time. This policy assumes the recent past will approximate the immediate future. The
operating system keeps track of when each page was referenced by recording the time of reference or by
maintaining a stack of references.
ALGORITHM:
1. Start the process
2. Declare the size
3. Get the number of pages to be inserted
4. Get the value
5. Declare counter and stack
6. Select the least recently used page by counter value
7. Stack them according the selection.
8. Display the values
9. Stop the process
PROGRAM:
#include<stdio.h>
#include<conio.h>
Void main()
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
clrscr();
printf("Enter the length of reference string -- ");
scanf("%d",&n);
printf("Enter the reference string -- ");
for(i=0;i<n;i++)
{
scanf("%d",&rs[i]); flag[i]=0;
}
printf("Enter the number of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is -- \n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
RESULT:
Thus a UNIX C program to implement LRU page replacement is executed successfully.
DESCRIPTION :
The FIFO Page Replacement algorithm associates with each page the time when that page was brought into
memory. When a page must be replaced, the oldest page is chosen . There is not strictly necessary to record
the time when a page is brought in. By creating a FIFO queue to hold all pages in memory and by replacing the
page at the head of the queue. When a page is brought into memory, insert it at the tail of the queue.
ALGORITHM:
1. Start the process
2. Declare the size with respect to page length
3. Check the need of replacement from the page to memory
4. Check the need of replacement from old page to new page in memory
5. Format queue to hold all pages
6. Insert the page require memory into the queue
7. Check for bad replacement and page fault
8. Get the number of processes to be inserted
9. Display the values
10. Stop the process
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
clrscr();
printf("\n Enter the length of reference string -- ");
scanf("%d",&n);
printf("\n Enter the reference string -- ");
for(i=0;i<n;i++)
scanf("%d",&rs[i]);
printf("\n Enter no. of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;
printf("\n The Page Replacement Process is -- \n");
for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
if(m[k]==rs[i])
break;
}
ALGORITHM
Step1: Start the program
Step2: Declare the required variables and initialize it.
Step3; Get the frame size and reference string from the user
Step4: Keep track of entered data elements
Step5: Accommodate a new element look for the element that is not to be used in frequently replace.
Step6: Count the number of page fault and display the value
Step7: Terminate the program
PROGRAM
#include<stdio.h>
#include<conio.h>
main()
{
int rs[50], i, j, k, m, f, cntr[20], a[20], min, pf=0;
clrscr();
printf("\nEnter number of page references -- ");
scanf("%d",&m);
printf("\nEnter the reference string -- ");
for(i=0;i<m;i++)
scanf("%d",&rs[i]);
printf("\nEnter the available no. of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
cntr[i]=0;
a[i]=-1;
}
Printf(“\nThe Page Replacement Process is – \n“);
for(i=0;i<m;i++)
{
for(j=0;j<f;j++)
if(rs[i]==a[j])
{
cntr[j]++;
break;
}
if(j==f)
{
min = 0;
for(k=1;k<f;k++)
if(cntr[k]<cntr[min])
Android Architecture
Android operating system is a stack of software components which is roughly divided into five sections and
four main layers as shown below in the architecture diagram
Linux kernel
At the bottom of the layers is Linux - Linux 2.6 with approximately 115 patches. This provides basic system
functionality like process management, memory management, device management like camera, keypad,
display etc. Also, the kernel handles all the things that Linux is really good at such as networking and a vast
array of device drivers, which take the pain out of interfacing to peripheral hardware.
Libraries
On top of Linux kernel there is a set of libraries including open -source Web browser engine WebKit, well
known library libc, SQLite database which is a useful repository for storage and sharing of application data,
libraries to play and record audio and video, SSL libraries responsible for Internet security etc.
Android Runtime
This is the third section of the architecture and available on the second layer from the bottom. This section
provides a key component called Dalvik Virtual Machine which is a kind of Java Virtual Machine specially
designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-threading, which is
intrinsic in the Java language. The Dalvik VM enables every Android application to run in its own process, with
its own instance of the Dalvik virtual machine.
Application Framework
The Application Framework layer provides many higher-level services to applications in the form of Java
classes. Application developers are allowed to make use of these services in their applications.
Platform libraries
The Platform Libraries include various C/C++ core libraries and Java-based libraries such as Media, Graphics,
Surface Manager, OpenGL, etc., to support Android development.
o app: Provides access to the application model and is the cornerstone of all Android applications.
o content: Facilitates content access, publishing and messaging between applications and application
components.
o database: Used to access data published by content providers and includes SQLite database,
management classes.
o OpenGL: A Java interface to the OpenGL ES 3D graphics rendering API.
o os: Provides applications with access to standard operating system services, including messages,
system services and inter-process communication.
o text: Used to render and manipulate text on a device display.
o view: The fundamental building blocks of application user interfaces.
o widget: A rich collection of pre-built user interface components such as buttons, labels, list views,
layout managers, radio buttons etc.
o WebKit: A set of classes intended to allow web-browsing capabilities to be built into applications.
o media: Media library provides support to play and record an audio and video format.
o surface manager: It is responsible for managing access to the display subsystem.
o SQLite: It provides database support, and FreeType provides font support.
o SSL: Secure Sockets Layer is a security technology to establish an encrypted link between a web server
and a web browser.
Android Applications
Android applications are usually developed in the Java language using the Android Software Development Kit.
Once developed, Android applications can be packaged easily and sold out either through a store such
as Google Play, SlideME, Opera Mobile Store, Mobango, F-droid or the Amazon Appstore.
Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It's the
largest installed base of any mobile platform and growing fast. Every day more than 1 million new Android
devices are activated worldwide.
Android Emulator
The Emulator is a new application in the Android operating system. The Emulator is a new prototype used to
develop and test android applications without using any physical device.
The android emulator has all of the hardware and software features like mobile devices except phone calls. It
provides a variety of navigation and control keys. It also provides a screen to display your application. The
emulators utilize the android virtual device configurations. Once your application is running on it, it can use
services of the android platform to help other applications, access the network, play audio, video, store, and
retrieve the data.
Aim:
To Install Virtual OS
Procedure:
VirtualBox (Free & Open Source): Popular and user-friendly, suitable for most home and
educational use cases.
VMware Workstation Player (Free for personal use): Powerful and feature-rich, offers more
advanced features.
Hyper-V (Windows): Built-in virtualization solution for Windows systems.
2. System Requirements
CPU: Ensure your processor supports virtualization (Intel VT-x or AMD-V). Check your
BIOS/UEFI settings to enable it.
RAM: Allocate sufficient RAM to the virtual machine (at least 4GB recommended).
Storage: Allocate enough disk space for the virtual machine's operating system and
applications.
Guest Additions: These are optional software packages that improve performance and
integration between the guest and host operating systems.
Install Guest Additions: Download and install Guest Additions within the guest operating
system.
Start the virtual machine: Launch the guest operating system within the virtual environment.
Experiment: Install software, run applications, test configurations, and explore the operating
system's features.
Snapshot and Restore: Create snapshots of your virtual machine to easily revert to a previous
state.
Remember:
This guide provides a general overview. Specific steps may vary depending on the chosen
virtualization software and the guest operating system. Refer to the documentation of your chosen
software for detailed instructions.
Procedure:
1. Choose an Emulator
2. System Requirements
CPU: Intel or AMD processor with virtualization technology (Intel VT-x or AMD-V) enabled in
BIOS.
RAM: At least 4GB of RAM (8GB or more recommended).
Storage: Sufficient disk space for the emulator and virtual device images.
Operating System: Windows, macOS, or Linux.
In Android Studio:
o Open the AVD Manager.
o Click "Create Virtual Device."
o Select a device definition (e.g., Pixel 6 Pro).
o Choose an Android system image (select the desired Android version and API level).
o Customize settings (e.g., RAM, storage, SD card).
In Android Studio:
o Select the AVD in the AVD Manager.
o Click "Start" to launch the emulator.
Genymotion/Bluestacks:
o Launch the emulator application.
o Select the desired virtual device.
Install apps: Install apps from the Google Play Store within the emulator (if supported).
Test applications: Run and test your own Android applications on the emulator.
Experiment with settings: Change device settings (e.g., location, screen rotation, network
connectivity) to simulate different scenarios.
Note:
Hardware Acceleration: Enable hardware acceleration in the emulator settings for better
performance.
Snapshots: Create snapshots of your emulator state to quickly revert to a previous
configuration.
Performance: Close unnecessary applications on your host machine to free up resources for
the emulator.
This guide provides a general overview. Specific steps may vary depending on the chosen
emulator and your operating system.
Refer to the official documentation for your chosen emulator for detailed instructions and
troubleshooting tips.
By following these steps, you can successfully install and simulate a mobile OS on your computer,
providing a valuable environment for testing and developing mobile applications.