Professional Documents
Culture Documents
OS LAB FILE
INDEX:
pg. 1
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 2
Pragya Rajput 2K21CSUN01087 CSE 4B
LAB -0
Lab-0
Laboratory Objective: To revisit and implement C Programming Concepts
Learning Outcome: To gain familiarity with the concepts of C.
Based on Functions
7. To find the Fibonacci using recursive function.
Based on Arrays
8. To insert a number at a given location in an array.
pg. 3
Pragya Rajput 2K21CSUN01087 CSE 4B
9. In a class there are 10 students. Each student is supposed to appear in three tests. Write a program
using 2D array to print
(a) The marks obtained by each student in different subjects.
10. Accept any two strings from the user. Display whether both the strings are equal or not. (do not
use standard functions).
Based on Structures
11. Write a program to accept a list of 10 integers in an array, pass the starting address of array in
sum function, calculate the sum of the array elements in the function and return the sum
calculated in the main function.
pg. 4
Pragya Rajput 2K21CSUN01087 CSE 4B
2. To calculate the bill amount for an item given the quantity sold, rate, discount and tax.
pg. 5
Pragya Rajput 2K21CSUN01087 CSE 4B
3. Program to enter any character. If the entered character is in lower case then convert it into upper case and
if it is lower case then convert it into upper case.
pg. 6
Pragya Rajput 2K21CSUN01087 CSE 4B
Based on Functions
pg. 7
Pragya Rajput 2K21CSUN01087 CSE 4B
Based on Arrays
8. In a class there are 10 students. Each student is supposed to appear in three tests. Write a program using 2D
array to print
(a) The marks obtained by each student in different subjects.
pg. 8
Pragya Rajput 2K21CSUN01087 CSE 4B
9. Accept any two strings from the user. Display whether both the strings are equal or not. (do not use
standard functions).
pg. 9
Pragya Rajput 2K21CSUN01087 CSE 4B
Based on Structures
10. Write a program to accept a list of 10 integers in an array, pass the starting address of array in sum function,
calculate the sum of the array elements in the function and return the sum calculated in the main function.
pg. 10
Pragya Rajput 2K21CSUN01087 CSE 4B
Lab-1
13. exec()
14. getpid()
15. exit()
16. wait()
pg. 11
Pragya Rajput 2K21CSUN01087 CSE 4B
1. fork()
2. exec()
pg. 12
Pragya Rajput 2K21CSUN01087 CSE 4B
3. getpid()
4. exit()
pg. 13
Pragya Rajput 2K21CSUN01087 CSE 4B
5. wait()
pg. 14
Pragya Rajput 2K21CSUN01087 CSE 4B
LAB-2
1. closedir()
• The closedir() function closes the directory stream associated with dirp. A
successful call to closedir() also closes the underlying file descriptor associated
with dirp. The directory stream descriptor dirp is not available after this call.
• The closedir() function returns 0 on success. On error, -1 is returned, and
errno is set to indicate the error.
2. opendir()
• The opendir() function opens a directory stream corresponding to the directory
name, and returns a pointer to the directory stream. The stream is positioned
at the first entry in the directory.
• The opendir() function return a pointer to the directory stream. On error,
NULL is returned, and errno is set to indicate the error.
pg. 15
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 16
Pragya Rajput 2K21CSUN01087 CSE 4B
3. readdir()
• The readdir() function returns a pointer to a dirent structure representing the
next directory entry in the directory stream pointed to by dirp. It returns NULL
on reaching the end of the directory stream or if an error occurred.
• On success, readdir() returns a pointer to a dirent structure.
pg. 17
Pragya Rajput 2K21CSUN01087 CSE 4B
Lab-3
Open():
The open() system call opens the file specified by pathname. If the specified
file does not exist, it may optionally be created by open()
The return value of open() is a file descriptor, a small non negative integer
that is an index to an entry in the process table of open file descriptors.
pg. 18
Pragya Rajput 2K21CSUN01087 CSE 4B
Read():
read() function shall attempt to read n bytes from the file associated wi8th the
open file descriptor, fildes into the buffer pointed to by buf
it reads data previously written into the file.
Write():
write() function shall attempt to write nbytes from the buffer pointed to by
buf to the file associated with the open file descriptor
pg. 19
Pragya Rajput 2K21CSUN01087 CSE 4B
Stat()
The stat() function shall obtain info about the named file and write it to the
area pointed to by buf argument
Upon successful completion,0 shall be returned.otherwise -1 shall be returned
Close()
The close() fuction shall deallocate the file descriptor indicated by fildes. To
deallocate means to make the file descriptor available for return by
subsequent calls
Lab-4
Laboratory Objective: To implement I/O system calls of UNIX
pg. 20
Pragya Rajput 2K21CSUN01087 CSE 4B
Write programs using the I/O System calls of UNIX operating system
1. stat()
2. close()
pg. 21
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 22
Pragya Rajput 2K21CSUN01087 CSE 4B
Lab-5 - Lab-8
Laboratory Objective: To implement scheduling algorithms in C.
1. Implement the following scheduling algorithms in C on the given scenario:
pg. 23
Pragya Rajput 2K21CSUN01087 CSE 4B
b) SJF
pg. 24
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 25
Pragya Rajput 2K21CSUN01087 CSE 4B
c) SRTF
pg. 26
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 27
Pragya Rajput 2K21CSUN01087 CSE 4B
d) RR
pg. 28
Pragya Rajput 2K21CSUN01087 CSE 4B
LAB-9
pg. 29
Pragya Rajput 2K21CSUN01087 CSE 4B
Producer-Consumer problem
Code-:
pg. 30
Pragya Rajput 2K21CSUN01087 CSE 4B
Output-:
pg. 31
Pragya Rajput 2K21CSUN01087 CSE 4B
Lab-10
FIRST FIT:
BEST FIT:
WORST FIT:
pg. 32
Pragya Rajput 2K21CSUN01087 CSE 4B
LAB-11
PAGE REPLACEMENT
pg. 33
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 34
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 35
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 36
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 37
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 38
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 39
Pragya Rajput 2K21CSUN01087 CSE 4B
pg. 40