SASTRA III Year OS Lab
-
Upload
saisastra3 -
Category
Documents
-
view
64 -
download
0
description
Transcript of SASTRA III Year OS Lab
![Page 1: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/1.jpg)
SHANMUGHA ARTS, SCIENCE, TECHNOLOGY & RESEARCH ACEDEMY (SASTRA) UNIVERSITY
(A University Established under section 3 of the UGC Act, 1956)TIRUMALAISAMUDRAM, THANJAVUR - 613401
Operating Systems Lab
BICCIC 505 R01 / BITCIT 505 R01 / BCSCCS 505 R02
2013-14
LIST OF EXPERIMENTS
1. Creation of a child process using fork system
call.
2. Implementing Producer-Consumer system.
3. Implementing Reader-Writer problem.
![Page 2: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/2.jpg)
4. Implementing Dining Philosopher problem.
5. IPC using Shared Memory System Call.
6. Working with Message Queues.
7. Simulate CPU Scheduling algorithms.
8. Simulate File Allocation strategies.
9. Simulate MVT and MFT.
10. Simulate Bankers Algorithm for Dead Lock
Avoidance.
11. Disk Scheduling Techniques
12. Simulate Page Replacement algorithms.
13. Simulate Paging technique of Memory Management.
14. Adding a new system call to Linux kernel
Additional Exercise
1.Study of Linux Kernel source code
![Page 3: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/3.jpg)
1. Creation of a child process using fork system call
Objective: Create a child process using fork system call and
ensure both parent and child process executing the same code.
Prerequisite:Knowledge of parent/child process, fork command
Procedure: Create the parent process and run the parent code Parent create child process using Fork(). Parent suspended to invoke child Child process invoked and displays child process Id
Pre-Lab: Process creation in Linux
Additional Exercise: Pipe Concept, File sharing, Multiple child processes creation
2. Simulating Producer-Consumer problem
Objective:Implementation of Producer-Consumer system thereby to
get the knowledge about multi-processes synchronization.
Prerequisite:Knowledge of Concurrency, Mutual exclusion,
Synchronization and producer-consumer problem
Procedure: Implement Semwait and semsignal functions Implement producer and consumer procedures Producer fills buffer using append Consumer consumes buffer content using take
Pre-Lab:Semaphore, multi-processes
Additional Exercise:Multiple producer and consumer
![Page 4: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/4.jpg)
3. Implementing Reader-Writer problem
Objective:To write a code which solve the readers writers
problem thereby which, concurrency problem is solved.
Pre-requisite:Knowledge of Concurrency, Mutual exclusion,
Synchronization and producer-consumer problem
Procedure: Create a reader process Create a writer process Implement Semsignal and semwait Implement program giving reader priority
Pre-Lab : Semaphore, multi-processes
Additional Exercise:Writer priority based implementation, multiple
readers and writers, Solution based on message passing
4. Implementing Dining Philosopher problem
Objective:To write a code for Dining philosopher problem,
thereby understanding how synchronization of processes is achieved.
Prerequisite:Knowledge of Concurrency, Deadlock and Starvation
Procedure: Array of semaphores are used to keep track of whether
a philosopher is eating ,thinking or hungry (trying to acquire the fork).
A philosopher may move only into the eating state if neither neighbour is eating.
Before starting ,to acquire the fork, a philosopher would do a DOWN on mutex.
After replacing the forks ,he would do an UP on mutex.Pre-Lab:
Semaphore, multi-processesAdditional Exercise:
Solution using monitors
![Page 5: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/5.jpg)
5. Inter-Process Communication using Shared Memory System Call
Objective: To achieve communication between two process using
shared memory concept, so that both process will use a common memory space.
Prerequisite:Knowledge of IPC, Shared memory, pipe concept
Procedure: Create the server process and create the shared
memory portion using shmget() function. Attach the shared memory segment to data space and
assign the shared memory a key value say “1234”. Write some data into the shared memory. Create the client process. Obtain the shared memory by passing the corresponding
key value “1234”. Attach the shared memory segment using shmat()
function. Read the data put by server in the memory. Alter a
character as an acknowledgement for having read the data.
Pre-Lab:shmat shmget.
Additional Exercise:IPC based on Message passing
6. Working with Message Queues
Objective: To implement message queues, which is an other means
of inter process communication that does not use file system.
Prerequisite:Knowledge of IPC, Message queues
Procedure: “queue reader” reads the messages from the queue
prints their contents to standard output. The "queue_reader" is given a number on its command line, which is the priority of messages that it should read.
![Page 6: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/6.jpg)
“queue sender” creates a message queue, and then starts sending messages with different priorities onto the queue.
Pre-Lab : Msgget(), Msgsnd(), Msgrcv()
Additional Exercise:A server program and two client programs, the server
can communicate privately to each client individually via a single message queue
7. Simulate CPU Scheduling algorithms
Objective:Simulation of CPU Scheduling algorithms thereby
understanding how allocation of tasks to the processor is done efficiently.
Prerequisite:Knowledge of scheduling algorithms
Procedure: Input the number of processes (p1, p2, … pn) Input the CPU process time for each of the process. Calculate the “waiting time” and the “average waiting
time” of all the process for the following scheduling types:
• First Come First Serve (FCFS)• Shortest Job First (SJF):• Round Robin• Priority based
Pre-Lab:Waiting Time, Burst Time and Average Waiting Time
calculation Additional Exercise: SRT, Feedback Queue
8. Simulate File Allocation strategies
Objective:Simulation of File Allocation using both linked
allocation and sequential allocation techniques.
Prerequisite:Knowledge File concepts, Allocation methods
Procedure:
![Page 7: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/7.jpg)
Create a Record and store the contents in the file. Create fixed sized blocks (arrays and structures).
Sequential Allocation:Records are stored in contiguous blocks.
Linked Allocation:Records are stored in free blocks and address of next block is stored at the end of the block.Pre-Lab:
Prior knowledge of Storage Schema of all File Allocation
methods. File operations – fopen(), fseek(),
ftell(), rewind(), fscanf(), etc,.
Additional Exercise:Indexed Allocation
9. Simulate MVT and MFT
Objective:Simulation of Multiprogramming with Variable and Fixed
number of Tasks.
Prerequisite:Concept multiprogramming, MVT and MFT
Procedure: Create various Tasks (copying file contents, storing
information in editor and drawing a picture, etc,.). Execute the Tasks (Threads) at an interval of time to
implement MVT. Get the opinions to execute notepad, paint
application for fixed number of tasks (MFT).
Pre-Lab:Multiprocesses, Fork, Pipe
Additional Exercise: Both MVT and MFT implemented and dynamically chosen
one of them
10. Simulate Banker’s Algorithm for Dead Lock Avoidance
Objective:To write a code for bankers algorithm which make
effective allocation of resource thereby avoids the deadlock.
Procedure: Get the number of processes and resources
![Page 8: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/8.jpg)
Create the following data structures: Available – Number of available resources of
each types. Max – Maximum demand of each process. Allocation – Number of resources of each type
currently allocated to each process. Need – Remaining resource need of each process.
(Max-Allocation) Use Safety algorithm and Resource-Request algorithm.
Pre-Lab:Prior knowledge of deadlocks and all deadlock
avoidance methods.
Additional Exercise:Deadlock detection, Deadlock recovery
11. Disk Scheduling Techniques
Objective:Write the code for some of the disk scheduling
algorithms which schedules disk space to the requesting process based on its algorithmic nature.
Prerequisite:Knowledge of disk scheduling algorithms.
Procedure:Implement scheduling algorithms listed below: First in First out Shortest Seek Time First Shortest Service Time First Scan
Pre-Lab:Seek time, transfer time etc.
Additional Exercise:C-SCAN, Look
12. Simulate Page Replacement algorithms
Objective:Simulate Page Replacement algorithms which
explores the concept of virtual memory and how it is achieved.
Prerequisite:Knowledge of Paging concepts, replacement algorithms
![Page 9: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/9.jpg)
Procedure: Create a queue of pages Select a page replace based on the following
approaches:Least Frequently Used, Least Recently Used and Optimal page replacement
Pre-Lab : Simple paging
Additional Exercise: FIFO, MRU, LFU, Second-chance and memory compaction.
13. Simulate Paging technique of Memory Management
Objective:Simulation of Paging technique of Memory Management,
which convert the logical address into physical address.
Prerequisite:Knowledge of Paging, Frames, Memory management
Procedure: Get the range of Physical and Logical addresses. Get the Page Size. Get the Page Number of the data. Construct Page Table by mapping Logical address to
Physical address. Search Page Number in the Page Table and locate the
Base Address. Calculate the Physical address of the data.
Pre-Lab:Paging, Page replacement, Address calculation methods
Additional Exercise:Simulation of thrashing, Implementation of
segmentation
14. Adding a new system call to Linux kernel
Objective:To develop our own system call and execute it by
adding it to the linux kernel.
Prerequisite:Knowledge of linux kernel, System calls
Procedure:
![Page 10: SASTRA III Year OS Lab](https://reader036.fdocuments.in/reader036/viewer/2022071803/55cf9cc9550346d033ab0c8c/html5/thumbnails/10.jpg)
1) Download the latest version of the 2.6 Linux kernel from www.kernel.org.
2) Unzip and untar the kernel directory into /usr/src/. 3) In /usr/src/Linux-x.x.x/kernel/, Create a new file
myservice.c to define your system call. 4)In /usr/src/Linux-x.x.x/include/asm/unistd.h, define
an index for your system call. Your index should be the number after the last system call defined in the list.
5)Also, you should increment the system call count. 6)In /usr/src/Linux-x.x.x/arch/i386/kernel/entry.S, you
should define a pointer to hold a reference to your system call routine.
7) Add your system call to the Makefile in /usr/src/Linux-x.x.x/kernel/Makefile. Add your object after the other kernel objects have been declared.
1) Make your system from /usr/src/Linux-x.x.x 2) Add a new boot image to Lilo, by editing
/etc/lilo.conf. Your lilo configuration will vary slightly.
3) Making a user test file. You also need to copy your edited unistd.h from /usr/src/Linux-x.x.x/include/asm/ to /usr/include/kernel/ because it contains your system call’s index. Reboot into your new kernel and compile your user test program to try out your system call. You will know if it worked if you see a kernel message in /var/log/kernel/warnings announcing that your service is running.
Pre-Lab:shell commands