Skip to content

Latest commit

 

History

History
228 lines (128 loc) · 9.99 KB

README.md

File metadata and controls

228 lines (128 loc) · 9.99 KB

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:

output1

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:

output2

2) CPU Scheduling Algorithms

File structure

structure

FCFS (First Come First Serve)

fcfs

SJF (Shortest Job First) - Non Preemptive/ Preemptive

sjf_np

sjf_p

Priority - Non Preemptive/ Preemptive

priority_np

priority_p

Round Robin

round_robin

3) Disk Scheduling

FCFS (first come first server)

fcfs

SSTF (Shortest seek time first)

sstf

SCAN - Direction Left/Right

scan_l

scan_r

Circular - SCAN

cscan

LOOK - Direction Left/Right

look_l

look_r

Circular - LOOK

clook

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:

ques1

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:

ques2

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:

ques3

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:

ques4

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.

ff

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

bf

Worst fit Allocation

It involves finding and allocating the largest available block of memory to the process in question.

wf

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.

fcfs

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.

lru

Optimal Replacement Algorithms

This algorithm replace the page that will be referenced furthest in the future or not at all.

optimal

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.

lfu

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:

1a

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:

1b

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:

1c

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:

1d

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:

1e

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:

2a

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:

2b