-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
743a1e5
commit 328700c
Showing
1 changed file
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
|
||
# Operating System Lab Programs/Codes | ||
|
||
This repository contains Programs for the Operating System Lab Course. Here I provide C Programs and some shell scripts and also the problem statement for some. If you find any error in code or the code is giving some Wrong Output you can raise a issue here. If you like it, consider giving a Star !! | ||
|
||
|
||
|
||
## Illustration | ||
|
||
### 1) Concurrency | ||
|
||
#### Dining Philosopher Problem | ||
|
||
Problem: | ||
|
||
The Dining Philosopher Problem states that K philosophers are seated around a circular table with one chopstick between each pair of philosophers. There is one chopstick between each philosopher. A philosopher may eat if he can pick up the two chopsticks adjacent to him. One chopstick may be picked up by any one of its adjacent followers but not both. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Producer Consumer Problem | ||
|
||
Problem: | ||
|
||
We have a buffer of fixed size. A producer can produce an item and can place in the buffer. A consumer can pick items and can consume them. We need to ensure that when a producer is placing an item in the buffer, then at the same time consumer should not consume any item. | ||
|
||
Output: | ||
|
||
 | ||
|
||
|
||
### 2) CPU Scheduling Algorithms | ||
|
||
#### File structure | ||
|
||
 | ||
|
||
#### FCFS (First Come First Serve) | ||
|
||
 | ||
|
||
#### SJF (Shortest Job First) - Non Preemptive/ Preemptive | ||
|
||
 | ||
|
||
 | ||
|
||
#### Priority - Non Preemptive/ Preemptive | ||
|
||
 | ||
|
||
 | ||
|
||
#### Round Robin | ||
|
||
 | ||
|
||
### 3) Disk Scheduling | ||
|
||
#### FCFS (first come first server) | ||
|
||
 | ||
|
||
#### SSTF (Shortest seek time first) | ||
|
||
 | ||
|
||
#### SCAN - Direction Left/Right | ||
|
||
 | ||
|
||
 | ||
|
||
#### Circular - SCAN | ||
|
||
 | ||
|
||
#### LOOK - Direction Left/Right | ||
|
||
 | ||
|
||
 | ||
|
||
|
||
#### Circular - LOOK | ||
|
||
 | ||
|
||
### 4) IPC (Inter Process Communication) | ||
|
||
#### Question 1 | ||
Write a C program using Pipes for the following | ||
a) Create 2 Process (Child and Parent) | ||
b) Child Process must request the Parent process to compute the | ||
factorial of a number. | ||
c) Child Process must read a number from the user. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 2 | ||
Write a C Program using Named Pipes (FIFOS) | ||
a) Create 2 Process(Sender and Receiver)(Un related - i.e, belonging | ||
to 2 separate applications) | ||
b) Sender process has to send u’r details (RegNo, Name, Course, | ||
School) to the Receiver process. | ||
|
||
Output: | ||
|
||
 | ||
|
||
|
||
#### Question 3 | ||
Use message queues in a C programme to construct a basic conversation | ||
programme between two unrelated, independent processes. Additionally, | ||
the programme must terminate until one of the processes posts the | ||
message "stop." | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 4 | ||
Write a C Program using Shared Memory b/w 2 processes for exchanging | ||
the below message: | ||
“Inter-Process Communication (IPC) plays a vital role in the world | ||
of operating systems, enabling different processes to communicate | ||
and cooperate with each other. IPC is crucial for multi-tasking, | ||
enabling processes to share data, synchronize their activities, | ||
and collaborate effectively” | ||
|
||
Output: | ||
|
||
 | ||
|
||
### 5) Memory Allocation | ||
|
||
#### First fit Allocation | ||
First-fit allocation is a memory allocation algorithm that goes through a list of free blocks of memory and assigns the task to the first block large enough to accommodate the request. | ||
|
||
 | ||
|
||
#### Best fit Allocation | ||
In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process | ||
|
||
 | ||
|
||
#### Worst fit Allocation | ||
It involves finding and allocating the largest available block of memory to the process in question. | ||
|
||
 | ||
|
||
|
||
### 6) Page Replacement Algorithms | ||
|
||
#### FIFO ( First in first out ) | ||
FIFO algorithm replaces the oldest (First) page which has been present for the longest time in the main memory. | ||
|
||
 | ||
|
||
#### LRU ( Least Recently used ) | ||
This algorithm is based on the strategy that whenever a page fault occurs, the least recently used page will be replaced with a new page. | ||
|
||
 | ||
|
||
#### Optimal Replacement Algorithms | ||
This algorithm replace the page that will be referenced furthest in the future or not at all. | ||
|
||
 | ||
|
||
#### LFU ( Least Frequently used ) | ||
The LFU algorithm counts how often an item is needed; those used less often are discarded first. This is similar to LRU, except that how many times a block was accessed is stored instead of how recently. | ||
|
||
 | ||
|
||
|
||
### 7) System Calls | ||
|
||
#### Question 1_A | ||
Write a function foo(int fd, char* buf, int b_size, int n, int skip) that reads to buf from file with file descriptor fd, n blocks of size b_size each. The last argument specifies how many bytes to skip after reading each block. Return -1 if the operation is unsuccessful. Else return total number of bytes read. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 1_B | ||
Write a program to read all txt files (that is files that ends with .txt) in the current directory and merge them all to one txt file and returns a file descriptor for the new file. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 1_C | ||
Write a program that takes a string as an argument and return all the files that begins with that name in the current directory and its sub directories. For example, > ./a.out foo will return all file names that begins with foo. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 1_D | ||
Write a program that will categorize all files in the current folder based on their file type. That is all .txt file in one folder called txt, all .bmp files in another folder called bmp etc. The argument to the program is a folder name. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 1_E | ||
Given a directory, write a program that will find all files with the same name in the directory and its sub directories. Show their name, which folder they are in and what day they were created. Expand the program to remove all duplicate copies based on user input. That is, ask user if each one of the file is to be kept or deleted. Based on user input, perform the appropriate action. | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 2_A | ||
Create two functions: one to generate the list of Odd_Numbers b/w 'n' and 'm', and another to generate Even_Numbers b/w 'n' and 'm'. In order to invoke the aforementioned techniques, construct a C programme that creates two processes, one of which calls the Even_Number list and the other the Odd_Number list | ||
|
||
Output: | ||
|
||
 | ||
|
||
#### Question 2_B | ||
Develop two distinct programmes. One should be used to generate Fibonacci Series upto 'n' terms (let's say Fibo.c), and the other should produce a list of PrimeNumbers b/w 'n' and 'm' (let's say Prime.c). Now develop a C programme that uses fork() to split into two processes, one that runs Fibo.c and the other that runs Prime.c. | ||
|
||
Output: | ||
|
||
 |