0% found this document useful (0 votes)
116 views68 pages

2302IT451 OS lab manual

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

2302IT451 OS lab manual

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

E.G.S.

PILLAY ENGINEERING COLLEGE (AUTONOMOUS)


NAGAPATTINAM
DEPARTMENT OF INFORMATION TECHNOLOGY

Regulation 2023

2302IT451 OPERATING SYSTEMS MANUAL

Prepared By

Dr.G.Arul Selvan, M.E., Ph.D

Assistant Professor/IT
Vision of the Department

To produce globally competent information technologist and to inculcate values of leadership and
research qualities in them

Mission of the Department

 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

The programme Educational Objectives (PEO)

● 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

PROGRAMME SPECIFIC OUTCOMES (PSOs)

After the successful completion, the graduates will have


PSO1: Propose appropriate Information processing, storage, retrieval and transmission techniques

PSO2: Use open source software tools

PSO3: Design, analyse and test software systems and products

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 2


2302IT452 OPERATING SYSTEMS LABORATORY LTPC

0031

List of Experiments:

1. Study of basic Commands in Unix Operating System


2. Shell Programming: Creating a script, making a script executable, shell syntax (variables, conditions,
control structures, functions, commands).
3. Implementation of CPU Scheduling Algorithms (FCFS, SJF, RR, Priority).
4. Simulation of Process synchronization using semaphores
5. Simulate Bankers Algorithm for Dead Lock Avoidance
6. Simulation of inter process communication using Shared Memory Concept
7. Simulate all file allocation strategies
8. Simulation of Page Replacement Algorithms (LRU, OPT, FIFO).
9. Install and Simulate Mobile OS, Virtual OS

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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 3


INTRODUCTION TO OPERATING SYSTEMS
AIM
To the study the various operating system.

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.

1.2 LINUX OPERATING SYSTEM


Linux is a free and open source operating system and it is a clone version of UNIX operating system. It
is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX
compatibility. Its functionality list is quite similar to that of UNIX.

1.2.1 LINUX ARCHITECTURE

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 4


The architecture of a linux system consists of the following layers −
 Hardware layer
Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
 Kernel
It is the core component of Operating System, interacts directly with hardware, provides low level
services to upper layer components.
 Shell
An interface to kernel, hiding complexity of kernel's functions from users. The shell takes commands
from the user and executes kernel's functions.
 Utilities
Utility programs that provide the user most of the functionalities of an operating systems.

1.2.2 COMPONENTS OF A LINUX OPERATING SYSTEM


Linux operating system has primarily three components:
 Kernel
Kernel is the core part of linux. It is responsible for all major activities of this operating system. It
consists of various modules and it interacts directly with the underlying hardware. Kernel provides the
required abstraction to hide low level hardware details to system or application programs.
 System Library
System libraries are special functions or programs using which application programs or system utilities
accesses Kernel's features. These libraries implement most of the functionalities of the operating
system and do not requires kernel module's code access rights.
 System Utility
System Utility programs are responsible to do specialized, individual level tasks.

1.2.3 KERNEL MODE VS USER MODE


Kernel component code executes in a special privileged mode called kernel mode with full access to all
resources of the computer. This code represents a single process, executes in single address space and do not
require any context switch and hence is very efficient and fast. Kernel runs each processes and provides
system services to processes, provides protected access to hardware to processes.

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.

1.2.4 BASIC FEATURES


Following are some of the important features of linux operating system
 Portable

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 5


Portability means software can work on different types of hardware in same way. Linux kernel and
application programs supports their installation on any kind of hardware platform.
 Open Source
Linux source code is freely available and it is community based development project. Multiple teams
work in collaboration to enhance the capability of Linux operating system and it is continuously
evolving.
 Multi User
Linux is a multiuser system means multiple users can access system resources like memory/ ram/
application programs at same time.
 Multiprogramming
Linux is a multiprogramming system means multiple applications can run at same time.
 Hierarchical File System
Linux provides a standard file structure in which system files/ user files are arranged.
 Shell
Linux provides a special interpreter program which can be used to execute commands of the
operating system. It can be used to do various types of operations, call application programs. etc.
 Security
Linux provides user security using authentication features like password protection/ controlled access
to specific files/ encryption of data.

1.3 COMPARISONS BETWEEN LINUX OS WITH DIFFERENT OS

1.3.1 LINUX VS WINDOWS

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 6


1.3.2 LINUX VS MAC

1.3.3 LINUX VS UNIX

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 7


EX.NO: 1 LINUX COMMANDS FILE SYSTEM

AIM
To study and implement about the various basic linux commands.

I. FILE RELATED COMMANDS


1. cat
 The cat command is used to create a file, display the contents of a file.
 The cat command is also used merge multiple files into a single file
Syntax
1.1 File Creation & Display its Contents using cat command
$ cat > filename (Create a new file)
$ cat <filename> (Display the contents of file)
$ cat file1 file2 >file3 (merge the contents of file1, file2 into file 3)
2. ls command
 Listing files and directories
 The ls command is used to display the contents of a directory.
Syntax
$ ls - View the contents of directory
3. clear command
 This command is used to clear the terminal screen
 $ clear

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 8


II. DIRECTORY RELATED COMMANDS
1. mkdir - Empty Directory Creation
 This command is used create an empty directory in a disk
Syntax
$ mkdir <dname>

2. rmdir - Empty Directory Deletion


 This command is used remove a directory from the disk
Rules for Directory Deletion
 Directory must be empty
 Directory can't be current working directory
Syntax
$ rmdir <dname>

3. cd - Changing the Working Directory


 This command is used to move from one directory to another directory.
Syntax
$ cd <dname>

4. pwd - Displaying Current Working Directory


 pwd stands for "print working directory". This command is used to print the current working directory
Syntax
$ cd <dname>

III. General Purpose Commands


1. date command
 This command is used to display the current date with day, month, date, time (24 Hrs clock) & year
Syntax
$ date

2. cal command - Displaying Current Month


 Linux calendar
 This command is used to display the current month, all months of particular year

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 9


Syntax
$ cal (Show the current month of current year)
$ cal 2015 (Show all months in year 2015)

RESULT
Thus the linux commands have been studied and executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 10


Ex No 2 PROCESS SYSTEM CALLS – FORK, EXEC, GETPID, EXIT, WAIT, AND CLOSE
AIM:
To write a program for implementing process management using the following system calls of UNIX
operating system: fork, exec, getpid, exit, wait, close.

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

PROCESS CONTROL SYSTEM CALLS


 It deals with process creation, process termination, etc, …

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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 11


 The caller of the newly created process is called as parent process
 It is identified by the return code is positive value

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.

WHICH PROCESS RUNS FIRST (b/w parent and child process)


 It an important to note that, there is no rule about which process runs first between parent
and child processes.
 As soon as a process is ready for execution (i.e. the fork system call returns), it may run
according to the scheduling configuration (priority, scheduler chosen, etc.).
 Depending on how the process is added to the scheduler, either process may be scheduled
first after returning from fork.

REQUIRED HEADER FILES


1. #include<stdio.h>
 This header file is used for printf(), scanf(), etc, …
2. #include<unistd.h>
 This header file is used for fork(), getpid(), getppid(), etc, …
3. #include<sys/types.h>
 This header file is used for pid_t, etc, …
4. #include<sys/wait.h>
 This header file is used for wait(), etc, …
5. #include<stdlib.h>
 This header file is used for exit(), etc, …

TOOLS SUPPORT
 Compiler : gcc compiler (gcc <filename>.c)
 Execution : ./a.out (assembly output)
 OS : Linux OS platform

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 12


Pictorial Representation

 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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 13


Usage of getpid() and getppid()
 Two major functions which are used to get the process ids. They are
1. getpid()
2. getppid()

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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 14


2. getppid()
 It is a built-in function and available in #include<unistd.h> header file
 It is used to return the process ID of parent process (caller of the 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>

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 15


Wait()
 It is system call and available in #include<sys/wait.h> file
 It blocks the current process (calling process), until one of its child processes terminate or a
signal is received
 It takes one argument which is the address of an integer variable (stores the information of
the process) and returns the process ID (PID) of completed child process
 Return type: pid_t
 If only one child process is terminated (finished its execution), then it returns the process ID
of the terminated child process
 If more than one child processes are terminated, then it returns process ID of any terminated
arbitrary child process.

The execution of wait() could have two possible situations.


1. If there are at least one child processes running when the call to wait() is made, the caller will
be blocked until one of its child processes exits. At that moment, the caller resumes its
execution.
2. If there is no child process running when the call to wait() is made, then this wait() has no
effect at all. It returns -1 immediately.

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 16


 The parameter 0 indicates that the termination is normal.

EXAMPLE OF WAIT AND EXIT SYSTEM CALLS


SOURCE CODE
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
int main()
{
pid_t pd;
printf("-----------------------------------------------\n");
printf("\twait() and exit()\n");
printf("-----------------------------------------------\n");
// execution of fork() call
if (fork()== 0)
{
printf("Child is calling...\n");
// normal termination
exit(0);
}
else
{
// get the PID of terminated child process
pd = wait(NULL);
printf("Parent is calling...\n");
// print the process IDs of parent and child processes
printf("Parent PID\t: %d\n", getppid());
printf("Child PID\t: %d\n", pd);
}
return 0;
}

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 17


EX.NO.3: I/O SYSTEM CALLS (OPEN, READ, WRITE, ETC).

Input/Output System Calls


Basically, there are total 5 types of I/O system calls:
1. C create
 The create() function is used to create a new empty file in C. We can specify the permission
and the name of the file which we want to create using the create() function.
 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 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

How C create() works in OS


 Create a new empty file on the disk.
 Create file table entry.
 Set the first unused file descriptor to point to the file table entry.
 Return file descriptor used, -1 upon failure.

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 18


Flags Description
O_RDONLY Opens the file in read-only mode.
O_WRONLY Opens the file in write-only mode.
O_RDWR Opens the file in read and write mode.
O_CREAT Create a file if it doesn’t exist.
O_EXCL Prevent creation if it already exists.
O_ APPEND Opens the file and places the cursor at the end of the contents.
O_ASYNC Enable input and output control by signal.
O_CLOEXEC Enable close-on-exec mode on the open file.
O_NONBLOCK Disables blocking of the file opened.
O_TMPFILE Create an unnamed temporary file at the specified path.

How C open() works in OS


 Find the existing file on the disk.
 Create file table entry.
 Set the first unused file descriptor to point to the file table entry.
 Return file descriptor used, -1 upon failure.

// C program to illustrate open system call


#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
extern int errno;
int main()
{
// if file does not have in directory // then file foo.txt is created.
int fd = open("foo.txt", O_RDONLY | O_CREAT);
printf("fd = %d\n", fd);
if (fd == -1) {
// print which type of error have in a code
printf("Error Number % d\n", errno);
// print program detail "Success or failure"
perror("Program");
}
return 0;
}
Output
fd = 3

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 19


3. C close
The close() function in C tells the operating system that you are done with a file descriptor and
closes the file pointed by the file descriptor. It is defined inside <unistd.h> header file.

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.

How C close() works in the OS


 Destroy file table entry referenced by element fd of the file descriptor table
– As long as no other process is pointing to it!
 Set element fd of file descriptor table to NULL

Example 1: close() in C // C program to illustrate close system Call


#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int fd1 = open("foo.txt", O_RDONLY);
if (fd1 < 0) {
perror("c1");
exit(1);
}
printf("opened the fd = % d\n", fd1);

// Using close system Call


if (close(fd1) < 0) {
perror("c1");
exit(1);
}
printf("closed the fd.\n");
}

Output
opened the fd = 3
closed the fd.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 20


4. C read
 From the file indicated by the file descriptor fd, the read() function reads the specified
amount of bytes cnt of input into the memory area indicated by buf.
 A successful read() updates the access time for the file. The read() function is also defined
inside the <unistd.h> header file.

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.

Example of read() in C // C program to illustrate read system Call


#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 21


5. C write
 Writes cnt bytes from buf to the file or socket associated with fd. cnt should not be greater
than INT_MAX (defined in the limits.h header file).
 If cnt is zero, write() simply returns 0 without attempting any other action.
 The write() is also defined inside <unistd.h> header file.

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.

Important Points about C write


 The file needs to be opened for write operations
 buf needs to be at least as long as specified by cnt because if buf size is less than the cnt then
buf will lead to the overflow condition.
 cnt is the requested number of bytes to write, while the return value is the actual number of
bytes written. This happens when fd has a less number of bytes to write than cnt.
 If write() is interrupted by a signal, the effect is one of the following:
 If write() has not written any data yet, it returns -1 and sets errno to EINTR.
 If write() has successfully written some data, it returns the number of bytes it wrote
before it was interrupted.

Example of write() in C // C program to illustrate write system Call


#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
int fd[2];
char buf1[12] = "hello world";
char buf2[12];

// assume foobar.txt is already created


fd[0] = open("foobar.txt", O_RDWR);
fd[1] = open("foobar.txt", O_RDWR);

write(fd[0], buf1, strlen(buf1));


2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 22
write(1, buf2, read(fd[1], buf2, 12));

close(fd[0]);
close(fd[1]);

return 0;
}

Output
hello world

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 23


4. SHELL PROGRAMMING BASICS
AIM
To execute the fundamentals of shell programming such as control flow statements.
EXISTING PROBLEM
 It is not possible to perform more than one task at a time using shell command
SHELL SCRIPTS (MULTITASKING)
 In order to solve the problems of shell command, the shell programming is introduced here
 Doing more than one job at a time (multitasking)
 It is also called as shell programming
VARIABLES SECTION
 Names given to the memory location
 Shell program supports dynamic data typed system which means that
 no need to use specific data type for variables declaration
Syntax
Variable_Name=Initial_Value
Example

I. EXAMPLE OF DATA TYPES IN SHELL CODE


SOURCE CODE
echo "------------------------------------"
echo "\tShell Data Types"
echo "------------------------------------"
# variables definition
a=19
b=15.45
c='S'
str="Sachin"
flag=true
# constant variable definition
readonly id=99
echo "Int\t\t\t\t-> $a"
echo "Float\t\t\t-> $b"
echo "Character\t\t-> $c"
echo "Name\t\t\t-> $str"
echo "Boolean\t\t\t-> $flag"
echo "Int Constant\t-> $id"

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 24


2. OUTPUT

COMMENT LINE STATEMENTS


 Usually these statements are ignored by compiler or interpreter
 Like c/c++, shell supports two types of comment line statements. They are
1. Single line statement
2. Multi line statements
1. Single line statement
 The single line statement is indicated by # symbol in shell program
Example
# - This is single line statement
2. Multi line statements
 It is used to ignore more than one statements
 This is indicated by :’ ’ symbol in shell program
Example

SELECTION STATEMENTS
1. Simple If statement
2. If else Statement
3. If else if Statement
4. Case Statement

1. Simple If Statement
Syntax

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 25


 It is an important to note that, the space should be given before and after the operator symbol [
 You can use test keyword instead of the operator symbols [ ]

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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 26


Where,
;; - represents the break part in case statements

LOOPING STATEMENTS
1. While loop (while)
2. Until loop (until)
3. For loop (for)

1. While loop
Syntax

Infinite While loop


 It is an important to note that, the colon (:) operator or true keyword is used for creating an infinite
loop
 The colon (:) operator is used instead of the operator symbols [ ]

II. EXAMPLE OF INFINITE LOOP USING WHILE LOOP

SOURCE CODE
while :
do
echo "Hello World"
done

(OR)

while true
do
echo "Hello World"

OUTPUT:

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 27


2. Until loop
 Here loop is executing until the condition is false
 If the condition becomes true it will exit from the loop
Syntax

III. EXAMPLE OF UNTIL LOOP


SOURCE CODE

OUTPUT

3. For loop
Syntax

Where,
Variable can be any user defined name
w1 w2 …wn - list of the values separated by spaces

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 28


Ex no 5 a IMPLEMENTATION OF FCFS SCHEDULING ALGORITHM

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("--------");
}

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 29


printf("\n");
for(i=0;i<n;i++)
{ printf(" P%d |",p[i]);
}
printf("\n");
for(i=0;i<n;i++)
{ printf("--------");
}
printf("\n");
for(i=0;i<=n;i++)
{ printf("%d\t",wat[i]);
}
awat=(float)twat/n;
atur=(float)ttur/n;
printf("\nTotal waiting time :%d\n",twat);
printf("\nTotal turnaround time :%d\n",ttur);
printf("\nAverage waiting time :%.2f\n",awat);
printf("\nAverage turn around time :%.2f\n",atur);
}

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

Total waiting time :25


Total turnaround time :48
Average waiting time :8.33
Average turn around time :16.00
RESULT:
Thus the program for FCFS scheduling has been executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 30


Exp: 5 b IMPLEMENTATION OF SJF SCHEDULING ALGORITHM

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++)
{

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 31


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("--------");
}
printf("\n");
for(i=0;i<n;i++)
{
printf(" P%d |",p[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<=n;i++)
{
printf("%d\t",wat[i]);
}
awat=(float)twat/n;
atur=(float)ttur/n;
printf("\nTotal waiting time :%d\n",twat);
printf("\nTotal turnaround time :%d\n",ttur);
printf("\nAverage waiting time :%.2f\n",awat);
printf("\nAverage turn around time :%.2f\n",atur);
}
OUTPUT:
[smk@cseserver3]$ cc prg3.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

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 32


Total waiting time :18
Total turnaround time:41
Average waiting time :6.00
Average turn around time:13.67
RESULT:
Thus the program for SJF scheduling has been executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 33


Exp: 5c IMPLEMENTATION OF PRIORITY SCHEDULING ALGORITHM

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];

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 34


pri[j]=t;
}
}
}
printf("\nPROCESS\tBURST TIME \t PRIORITY \t WAITING TIME \tTURNAROUND
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\t\t%d\n",p[i],bur[i],pri[i],wat[i],tur[i]);
}
printf("\nGAANT CHART\n\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<n;i++)
{
printf(" P%d |",p[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<=n;i++)
{
printf("%d\t",wat[i]);
}
awat=(float)twat/n;
atur=(float)ttur/n;
printf("\nTotal waiting time :%d\n",twat);
printf("\nTotal turnaround time :%d\n",ttur);
printf("\nAverage waiting time :%.2f\n",awat);

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 35


printf("\nAverage turn around time :%.2f\n",atur);
}
OUTPUT:
[smk@cseserver3]$ cc prg6.c
[smk@cseserver3]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 14
Enter the burst time for process 2: 26
Enter the burst time for process 3: 34
Enter the priority for process 1: 3
Enter the priority for process 2: 1
Enter the priority for process 3: 2

Total waiting time :86


Total turnaround time :160
Average waiting time :28.67
Average turn around time :53.33

RESULT:
Thus the program for priority scheduling is successfully implemented.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 36


Exp: 5d IMPLEMENTATION OF ROUND ROBIN SCHEDULING ALGORITHM
AIM:
To write a ‘C’ program to implement ROUND ROBIN Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating ROUND ROBIN scheduling scheme.
Step 2: Declare the variables to calculate the essential aspects of ROUND ROBIN.
Step 3: Initially get the time slice along with process time and burst time.
Step 4: Start from the 1st process and execute it for the given time slice and move to 2nd process
and so on till all process gets executed for each of the time slice allotted.
Step 5: Prepare the gantt chart for each process getting executed within the time slice in a round
robin fashion.
Step 6: Calculate the waiting time and turn around time along with their averages display the
result.

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;

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 37


while(j<m)
{
if(x==n-1)
x=0;
else
x++;
if(bur[x]>=t)
{
bur[x]=bur[x]-t;
a[j+1]=a[j]+t;
if(b[x]==1)
{
p[s]=x;
k[s]=a[j+1];
s++;
}
j++;
b[x]=b[x]-1;
printf(" P%d |",x+1);
}
else if(bur[x]!=0)
{
a[j+1]=a[j]+bur[x];
bur[x]=0;
if(b[x]==1)
{
p[s]=x;
k[s]=a[j+1];
s++;
}
j++;
b[x]=b[x]-1;
printf(" P%d |",x+1);
}
}
printf("\n");
for(i=0;i<m;i++)
printf("--------");
printf("\n");
for(j=0;j<=m;j++)
printf("%d\t",a[j]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(p[i]>p[j])

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 38


{
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=k[i];
k[i]=k[j];
k[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
wat[i]=k[i]-bur1[i];
tur[i]=k[i];
}
printf("\nPROCESS\tBURST TIME \t WAITING TIME \t TURN AROUND TIME\t");
for(i=0;i<n;i++)
{ printf("\n%d\t\t%d\t\t%d\t\t%d\t\n",p[i]+1,bur1[i],wat[i],
tur[i]); }
for(i=0;i<n;i++)
{
ttur=ttur+tur[i];
twat=twat+wat[i];
}
awat=(float)twat/n;
atur=(float)ttur/n;
printf("\nTotal waiting time:%d",twat);
printf("\nTotal turnaround time:%d",ttur);
printf("\nAverage waiting time :%.2f",awat);
printf("\nAverage turn around time :%.2f",atur);
}
OUTPUT:
[smk@cseserver3]$ cc prg7.c
[smk@cseserver3]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 4
Enter the burst time for process 2: 7
Enter the burst time for process 3: 1
Enter the slicing time :2

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 39


PROCESS BURST TIME WAITING TIME TURN AROUND TIME
1 4 3 7
2 7 5 12
3 1 4 5

Total waiting time:12


Total turnaround time:24
Average waiting time :4.00
Average turn around time :8.00
RESULT:
Thus program for round robin scheduling is performed.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 40


EX.NO:06 PROCESS SYNCHRONIZATION USING SEMAPHORE
AIM:
To write a C program to implement the Producer & consumer Problem (Semaphore)

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);

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 41


printf(“\nEnter an item:”);
scanf(“%d”,&item);
buffer[in]=item;
in=in+1;
signal(mutex);
signal(full);
} while(in<n);
}
void consumer()
{
do {
wait(full);
wait(mutex);
item1=buffer[out];
printf(“\nConsumed item =%d”,item1);
out=out+1;
signal(mutex);
signal(empty);
} while(out<n);
}
void main()
{
printf(“Enter the value of n:”);
scanf(“%d “,&n);
empty=n;
while(in<n)
producer();
while(in!=out)
consumer();
}
OUTPUT:
$ cc prco.c
$ a.out
Enter the value of n :3
Enter the item:2
Enter the item:5
Enter the item:9
consumed item=2
consumed item=5
consumed item=9
$
RESULT:
Thus the program for solving producer and consumer problem using semaphore was executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 42


EX.NO: 07 DEADLOCK AVOIDANCE – BANKERS ALGORITHM
AIM:
To Simulate Algorithm for Deadlock avoidance

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

2) Find i such that


a) Finish[i] = false
b) Need [i] <= Work
if no such i exists
goto step (4)

3) Work = Work + Allocation[i]


Finish[i] = true
goto step (2)

4) if Finish [i] = true for all i


the system is in a safe state

Resource-Request Algorithm

Let us consider a vector Request for Process Pi.


Requesti[j]= k means process Pi requires k instances of Resource Rj.
1) If Request[i] <= Need[i]
2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 43
Goto step (2) ;
else
raise error condition as the process exceeds its maximum claim.

2) If Request[i] <= Available


Goto step (3);
else wait as the resources are not available.
3)Pretend to have allocated the resources that are requested to process Pi by modifying the state as
Available = Available – Request[i]
Allocation[i] = Allocation[i] + Request[i]
Need[i] = Need[i]– Request[i]

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");

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 44


for (i=0;i <process;i++) {
printf("P[%d] ",i);
for (j=0;j<no_of_resources;j++)
scanf("%d", &MAX[i][j]);
}
printf("\n");
A: a=-1;
for (i=0;i <process;i++) {
cnt=0;
b=P[i];
for (j=0;j<no_of_resources;j++) {
need[b][j] = MAX[b][j]-allocated[b][j];
if(need[b][j]<=availability[j])
cnt++;
}
if(cnt==no_of_resources) {
op[k++]=P[i];
for (j=0;j<no_of_resources;j++)
availability[j]+=allocated[b][j];
} else
P[++a]=P[i];
}
if(a!=-1) {
process=a+1;
goto A;
}
printf("\t <");
for (i=0;i<k;i++)
printf(" P[%d] ",op[i]);
printf(">");
getch();
}

OUTPUT
Enter the number of resources: 3

Enter the max instances of each resource


a= 10
b= 5
c= 7

Enter the number of processes: 5

Enter the allocation matrix


abc
P[0] 0 1 0

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 45


P[1] 200
P[2] 302
P[3] 211
P[4] 002

Enter the MAX matrix


abc
P[0] 7 5 3
P[1] 3 2 2
P[2] 9 0 2
P[3] 4 2 2
P[4] 5 3 3

< P[1] P[3] P[4] P[0] P[2] >

RESULT:
Thus the program for solving Bankers algorithm for deadlock avoidance was executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 46


Ex.No: 08 DEVELOPING APPLICATION USING INTERPROCESS COMMUNICATION

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);

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 47


while(n>2)
{
c=a+b;
printf(“\n %d”,c);
a=b;
b=c;
n--;
}
}
}
OUTPUT:
[smk@networkserver ~]$ cc fib.c
[smk@networkserver ~]$ ./a.out
Parent process
Fibonacci series
Enter the limit for the series: 6
Child process
[smk@networkserver ~]$ Fibonacci series
0
1
1
2
3
5

RESULT:
Thus the program to implement interprocess communication is executed.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 48


Ex. No : 9 a SEQUENTIAL FILE ALLOCATION

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:");

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 49


for(i=0;i<b[x-1];i++)
printf("%4d",c[x-1][i]);
getch();
}

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

File name is: 12803 length is:0blocks occupied

RESULT:
Thus the program to implement sequential file allocation is executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 50


Ex. No : 9 b SEQUENTIAL FILE ALLOCATION

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 52


Ex. No : 9 c LINKED FILE ALLOCATION

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++)

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 53


{
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n");
}
getch();
}

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 54


Ex.No 10 a IMPLEMENTATION OF LRU PAGE REPLACEMENT ALGORITHM

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++)
{

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 55


if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
next++;
}
}
if(flag[i]==0)
{
if(i<f)
{
m[i]=rs[i];
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
min=j;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i]==0)
printf("PF No. -- %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
getch();
}
OUTPUT
Enter the length of reference string -- 20
Enter the reference string -- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Enter the number of frames -- 3
The Page Replacement process is --
7 -1 -1 PF No. -- 1
7 0 -1 PF No. -- 2
7 0 1 PF No. -- 3
2 0 1 PF No. -- 4
201

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 56


2 0 3 PF No. -- 5
203
4 0 3 PF No. -- 6
4 0 2 PF No. -- 7
4 3 2 PF No. -- 8
0 3 2 PF No. -- 9
032
032
1 3 2 PF No. -- 10
132
1 0 2 PF No. -- 11
102
1 0 7 PF No. -- 12
107
107
The number of page faults using LRU are 12

RESULT:
Thus a UNIX C program to implement LRU page replacement is executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 57


EX.NO:10 b IMPLEMENTATION OF THE FIFO PAGE REPLACEMENT ALGORITHMS
AIM:
To write a UNIX C program to implement FIFO page replacement algorithm.

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;
}

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 58


if(k==f)
{
m[count++]=rs[i];
pf++;
}
for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF No. %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of Page Faults using FIFO are %d",pf);
getch();
}
OUTPUT
Enter the length of reference string – 20
Enter the reference string -- 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Enter no. of frames -- 3
The Page Replacement Process is –
7 -1 -1 PF No. 1
7 0 -1 PF No. 2
7 0 1 PF No. 3
2 0 1 PF No. 4
201
2 3 1 PF No. 5
2 3 0 PF No. 6
4 3 0 PF No. 7
4 2 0 PF No. 8
4 2 3 PF No. 9
0 2 3 PF No. 10
023
023
0 1 3 PF No. 11
0 1 2 PF No. 12
012
012
7 1 2 PF No. 13
7 0 2 PF No. 14
7 0 1 PF No. 15
The number of Page Faults using FIFO are 15
RESULT:
Thus a UNIX C program to implement FIFO page replacement is executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 59


EX.NO:10 C IMPLEMENTATION OF OPTIMAL (LFU) PAGE REPLACEMENT ALGORITHM
AIM:
To write a program in C to implement LFU page replacement algorithm.

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])

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 60


min=k;
a[min]=rs[i];
cntr[min]=1;
pf++;
}
printf("\n");
for(j=0;j<f;j++)
printf("\t%d",a[j]);
if(j==f)
printf(“\tPF No. %d”,pf);
}
printf("\n\n Total number of page faults -- %d",pf);
getch();
}
OUTPUT
Enter number of page references -- 10
Enter the reference string -- 1 2 3 4 5 2 5 2 5 1 4 3
Enter the available no. of frames 3
The Page Replacement Process is –
1 -1 -1 PF No. 1
1 2 -1 PF No. 2
1 2 3 PF No. 3
4 2 3 PF No. 4
5 2 3 PF No. 5
523
523
5 2 1 PF No. 6
5 2 4 PF No. 7
5 2 3 PF No. 8
Total number of page faults -- 8
RESULT:
Thus the C programs to implement LFU page replacement algorithm was executed successfully.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 61


Ex.No: 11 Study of Android OS

Aim: Introduction to android Operating system

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 62


The Android runtime also provides a set of core libraries which enable Android application developers to write
Android applications using standard Java programming language.

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 63


Advantages of Android Operating System
We considered every one of the elements on which Android is better as thought about than different
platforms. Below are some important advantages of Android OS, such as:
o Android Google Developer: The greatest favourable position of Android is Google. Google claims an
android operating system. Google is a standout amongst the most trusted and rumoured item on the
web. The name Google gives trust to the clients to purchase Android gadgets.
o Android Users: Android is the most utilized versatile operating system. More than a billion individuals
clients utilize it. Android is likewise the quickest developing operating system in the world. Various
clients increment the number of applications and programming under the name of Android.
o Android Multitasking: The vast majority of us admire this component of Android. Clients can do heaps
of undertakings on the double. Clients can open a few applications on the double and oversee them
very. Android has incredible UI, which makes it simple for clients to do multitasking.
o Google Play Store App: The best part of Android is the accessibility of many applications. Google Play
store is accounted for as the world's largest mobile store. It has practically everything from motion
pictures to amusements and significantly more. These things can be effortlessly downloaded and
gotten to through an Android phone.
o Android Notification and Easy Access: Without much of a stretch, one can access their notice of any
SMS, messages, or approaches their home screen or the notice board of the android phone. The client
can view all the notifications on the top bar. Its UI makes it simple for the client to view more than 5
Android notices immediately.
o Android Widget: Android operating system has a lot of widgets. This gadget improves the client
encounter much and helps in doing multitasking. You can include any gadget relying on the
component you need on your home screen. You can see warnings, messages, and a great deal more
use without opening applications.

Disadvantages of Android Operating System


We know that the Android operating system has a considerable measure of interest for users nowadays. But
at the same time, it most likely has a few weaknesses. Below are the following disadvantages of the android
operating system, such as:
o Android Advertisement pop-ups: Applications are openly accessible in the Google play store. Yet,
these applications begin demonstrating tons of advertisements on the notification bar and over the
application. This promotion is extremely difficult and makes a massive issue in dealing with your
Android phone.
o Android require Gmail ID: You can't get to an Android gadget without your email ID or password.
Google ID is exceptionally valuable in opening Android phone bolts as well.
o Android Battery Drain: Android handset is considered a standout amongst the most battery devouring
operating systems. In the android operating system, many processes are running out of sight, which
brings about the draining of the battery. It is difficult to stop these applications as the lion's share of
them is system applications.
o Android Malware/Virus/Security: Android gadget is not viewed as protected when contrasted with
different applications. Hackers continue attempting to take your data. It is anything but difficult to
target any Android phone, and each day millions of attempts are done on Android phones.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 64


Ex 12 Install and Simulate Mobile OS, Virtual OS

Aim:
To Install Virtual OS

Procedure:

1. Choose a Virtualization Software

 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.

3. Download and Install the Virtualization Software

 Download the chosen software from the official website.


 Follow the on-screen instructions to install it on your host machine.

4. Create a Virtual Machine

 Launch the virtualization software.


 Create a new virtual machine:
o Name and OS: Give your virtual machine a name and select the guest operating
system (e.g., Windows, Linux, macOS).
o Memory: Allocate RAM to the virtual machine.
o Hard Disk: Create a virtual hard disk (VDI, VHD, etc.) and choose its size.
 Customize Settings (Optional):
o Network: Configure network settings (NAT, bridged, host-only).
o Storage: Add virtual CD/DVD drives to install the guest OS.

5. Install the Guest Operating System

 Insert the installation media:


o If using an ISO image, mount it in the virtual CD/DVD drive.
o If using a physical media (CD/DVD), insert it into your host machine's drive.
 Boot the virtual machine: Start the virtual machine and boot from the installation media.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 65


 Follow the on-screen instructions: Install the guest operating system within the virtual
machine.

6. Install Guest Additions (Optional)

 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.

7. Simulate and Experiment

 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.

Example: Installing and Simulating Ubuntu Linux on VirtualBox

1. Download and install VirtualBox.


2. Create a new virtual machine:
o Name: "UbuntuVM"
o Type: Linux
o Version: Ubuntu (64-bit)
3. Allocate resources:
o Memory: 2GB RAM
o Hard Disk: Create a new virtual hard disk (VDI), dynamically allocated, 20GB size.
4. Download Ubuntu ISO: Obtain an Ubuntu ISO image from the official Ubuntu website.
5. Start the VM: Boot from the Ubuntu ISO.
6. Install Ubuntu: Follow the on-screen instructions to install Ubuntu within the virtual machine.
7. Install VirtualBox Guest Additions: After installation, run the Guest Additions installer within
the Ubuntu VM.
8. Simulate: Use the Ubuntu VM to experiment with Linux commands, install applications, and
explore its features.

Remember:

 Resource Allocation: Allocate resources (RAM, CPU) appropriately to avoid performance


issues on your host machine.
 Snapshots: Regularly create snapshots to easily revert to previous states.
 Security: Keep your virtualization software and guest operating systems updated with the
latest security patches.

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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 66


Mobile OS
Aim:
To Install Mobile OS

Procedure:

1. Choose an Emulator

 Android Studio Emulator:


o Pros: Official emulator from Google, highly compatible, offers advanced features.
o Cons: Can be resource-intensive.
 Genymotion:
o Pros: Faster and more lightweight than the Android Studio emulator, offers a wider
range of device profiles.
o Cons: Requires a paid subscription for commercial use.
 Bluestacks:
o Pros: Popular and easy to use, optimized for gaming.
o Cons: Can be resource-intensive, may have performance issues with some apps.

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.

3. Install the Emulator

 Android Studio Emulator:


o Install Android Studio.
o Install the necessary Android SDK components.
o Create an Android Virtual Device (AVD) in the AVD Manager.
 Genymotion:
o Download and install Genymotion.
o Create and configure virtual devices.
 Bluestacks:
o Download and install Bluestacks from the official website.

4. Create an AVD (Android Virtual Device)

 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).

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 67


o Click "Finish" to create the AVD.

5. Run the Emulator

 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.

6. Simulate and Test

 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.

2302IT451 OS Lab/IT/EGSPEC G.Arul Selvan AP/IT Page 68

You might also like