OS kiran
OS kiran
Submitted To:
Prof. Naveed Akhtar
Submitted By:
Kiran Haleem
Student ID:
2023-CS-F087
Email ID:
Kiranrashidkr0@gmail.com
Department:
Bachelors in Computer Science
Subject:
Operating Systems
Submitted Date:
12/05/2025
Subm i tted i n parti al ful fi l l m ent of the requi r em ents fo r the degr ee of
BS Com puter Sci ence/ Software Engi neeri ng
at School of Com puter and I nform ati on Technol og y (SCI T), M ul tan Uni versi ty of Sci ence and Techno l ogy
(M UST), M ul tan.
P a g e 1 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Contents:
P a g e 2 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 1:
When you open the terminal, what directory are you in by default? Use appropriate command to print it.
Steps:
Task 2:
Go to /etc./apt directory and display the list of contents using appropriate commands
Step:
Task 3:
Tell who is logged into the Linux system using the terminal?
To identify users currently logged into the Linux system using terminal commands.
Task 4:
Create a directory with your name on the Desktop while you are inside the Desktop directory.
Task 5:
Create a directory with your surname inside your name directory created in task 4 while you are inside
P a g e 4 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
the root directory.
Absolute Relative
An absolute path is the full path to a file or A relative path describes the location of a file
directory starting from the root ( /) of the file or directory in relation to your current
system. working directory.
It always begins with /, which represents the It does not begin with /.
root directory. It depends on where you are in the terminal.
It is independent of your current location in
the terminal.
P a g e 5 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab 2:
Exploring the use of different Linux commands to use the OS through the
terminal
Lab Objective: To introduce students with different Linux commands to control the OS through the terminal.
Command Explanation
sudo useradd <username> Adding a new user
sudo passwd <username> Setting a password for the new user
sudo userdel <username> Deleting the user
sudo groupadd <groupname> Adding a new group
Task 1:
Locate a file named passwd using the appropriate command.
Task 2:
Create a text file named “my_info.txt”.
Open it and enter your name, registration number and age.
Save it.
Copy it to the Documents Directory.
Delete the original file.
P a g e 6 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 3:
Use nano command to create a file named “file1” and write Hello world.
Use touch command to create another file named “file2”.
Create a directory named folder1 and move both files to the directory using appropriate command.
Compress the directory folder1.
Steps:
Create file1 using nano and write "Hello world"
Create file1 using nano and write "Hello world"
Create file2 using touch
Create a directory named folder1
Move both file1 and file2 into folder1
Compress the directory folder1
Task 4:
Unzip the directory in task 3.
Delete the file named “file2” and leave the file1 as it is.
Show what is written in the file1.
Delete the directory containing “file1”.
P a g e 7 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab 3:
Implementation of UNIX Streams, Pipes and Redirects in Linux terminal
P a g e 8 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab Objective: To introduce students with different Linux commands to control the OS through terminal.
Introduction:
The humble pipe character, |, is easy to overlook in long chains of Unix-style commands. But what the pipe
enables – easy communication between independent programs – is essentially what made it possible (for better or
for worse), for Unix to have the toolbox that it has.
Most shells offer the ability to alter the way that application input and output flows. This can direct output away
from the terminal and into files or other applications, or otherwise reading input from files instead of the terminal.
Task 1:
Create a new user in your Linux using your name and some password. Using the command discussed in
last lab.
Create a text file named ‘your name.txt’ using vi editor and say hello to yourself.
Enlist the contents of the directory /usr/share/ufw/ and redirect the output to the created text file.
Open the text file using vi editor and show what is inside the file.
Task 2:
Write down the text “The list of log files”, in the file created above without opening it.
Append the output containing the files of the /var/log/ directory to the file created above.
Append the text “the list ends here”.
Open the file using vi editor and show what it contains now.
P a g e 9 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 3:
Write your name, surname, department, university name in a text file using echo command and then count
how many words you wrote using appropriate command.
Note: all should be done using a single line command.
Task 4:
Create a file named “My friends”, write down names of at least 10 friends of yours.
Use cat command output to arrange them in alphabetical order using appropriate command, then show the
names which have ‘m’ latter in them.
Note: All commands should be written in a single line. Output must show only the names containing ‘m’ letter.
P a g e 10 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab Objective:
To learn how processes are managed in Linux Operating systems.
Introduction
Linux in general is a fairly stable system. Occasionally, things do go wrong however and sometimes we also wish
to tweak the running of the system to better suit our needs. In this section we will take a brief look at how we may
manage programs, or processes on a Linux system.
Task 1: Start a few programs in your desktop. Then use ps to identify their PID and kill them.
Task 1:
Imagine you are a system administrator responsible for monitoring and managing a Linux server. As part of your
routine tasks, you need to list and inspect the currently running processes on the system. Your objective is to use
appropriate Linux commands to enlist the processes and display their relevant attributes. In this exercise, you will
generate a report with screenshots of at least two screens that show the process listing, one screen at a time.
Deliverables:
1. A report document that includes at least two screenshots of the process listing, along with explanations
and captions.
2. The Linux commands used to generate the process listings.
3. Any observations or analysis of the process listing data.
Screenshot 1:
The top command provides a dynamic real-time view of system processes. It lists:
PID: Process ID
USER: Owner of the process
%CPU: CPU usage percentage
%MEM: Memory usage
COMMAND: Name of the running process
P a g e 12 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Screenshot 2:
The ps aux command lists all system processes with details such as:
User
PID
CPU/Memory usage
Process status
Time started
Full command path
Task 2:
Imagine you are a system administrator who needs to create a new user on a Linux system, assign a password to
that user, log in to the newly created user account, and display the current working directory. Your goal is to write
a Bash script that performs these steps and provides informative text before executing each command for better
understanding and documentation.
You will be assessed on your ability to write a well-documented Bash script that accomplishes the specified tasks.
The clarity of comments and the accuracy of the commands will be evaluated. The script should effectively create
a new user, set a password, log in to the user account, and display the current working directory with informative
descriptions at each step.
P a g e 13 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
P a g e 14 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 1:
Imagine you are a system administrator responsible for setting up a Linux for a team of developers who
will be working on C and C++ projects. Your task is to install the GCC (GNU Compiler Collection) to
enable software development using these programming languages.
Deliverables:
1. A script or set of instructions for installing the GCC compiler on the Linux.
2. A verification section showing the successful installation of GCC.
3. Any additional components or packages installed.
4. Documentation within the script or instructions explaining the purpose of each command.
5. A statement indicating the successful completion of the task.
Verification of Installation
gcc –version
P a g e 15 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 2:
Imagine you are a system administrator responsible for configuring a Linux development for a team of
programmers. The developers prefer using Vim as their text editor for coding and require it to be installed on
Linux.
Deliverables:
1. A script or set of instructions for installing Vim on Linux.
2. A verification section showing the successful installation of Vim.
3. Any optional components or plugins installed.
4. Documentation within the script or instructions explaining the purpose of each command.
5. A section for basic Vim customization.
6. A statement indicating the successful completion of the task.
vim –version
P a g e 16 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
P a g e 17 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 1:
Create a new text file using yourname as <yourname.txt> on your root directory
Move the file from root to Desktop directory using appropriate command.
Create a C code for opening, writing, reading and then closing the text file created above.
Write the text “My name is <yourname>. My registration number is <reg no.>.
Task2:
Implement wait system call using C on your Linux distro.
P a g e 18 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
P a g e 19 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
DESCRIPTION:
To calculate the average waiting time using the FCFS (First Come First Serve) algorithm first the waiting time of
the first process is kept zero and the waiting time of the second process is the burst time of the first process and
the waiting time of the third process is the sum of the burst times of the first and the second process and so on.
After calculating all the waiting times the average waiting time is calculated as the average of all the waiting
times. FCFS mainly says first come first serve the algorithm which came first will be served first.
Task 1:
Run the C++ code for FCFS with arrival time and explain the process and the output in detail.
Input Section:
Sorting:
P a g e 20 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
The processes are sorted based on their arrival time to simulate the FCFS order.
Calculation:
Output Table:
Averages:
Task 2:
Write the C/C++ program for SJF following the algorithm given and discuss the process and output.
P a g e 21 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
The user inputs the number of processes and their burst times.
Calculation:
Output:
P a g e 22 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab 9:
Implementation of Process Scheduling Algorithms ROUND ROBIN and
PRIORITY (Open Ended)
OBJETIVE: To simulate the CPU scheduling algorithm round-robin and Priority Algorithm.
Round Robin:
To aim is to calculate the average waiting time. There will be a time slice, each process should be executed within
that time-slice and if not, it will go to the waiting state so first check whether the burst time is less than the time-
slice. If it is less than it assigns the waiting time to the sum of the total times. If it is greater than the burst-time
then subtract the time slot from the actual burst time and increment it by time-slot and the loop continues until all
the processes are completed.
Task 1:
Run the C code for Round Robin and explain the process and the output in detail.
Round Robin (RR) is a preemptive CPU scheduling algorithm used in time-sharing systems. Each process gets a
small unit of CPU time (called time quantum). Once a process has used up its quantum, it's moved to the back
of the ready queue if it’s not finished.
C++ code:
P a g e 23 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Output:
Task 2:
Write the C program for PRIORITY following the algorithm given above and discuss the process and output.
Explanation :
simulate Priority Scheduling, a CPU scheduling algorithm where each process is assigned a priority, and the
CPU is allocated to the process with the highest priority (typically the lowest numeric value).
C++ Code:
P a g e 24 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Output:
P a g e 25 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
The Producer-Consumer problem is a classic problem that is used for multi-process synchronization i.e.
synchronization between more than one process.
In the producer-consumer problem, there is one Producer that is producing something and there is one Consumer
that is consuming the products produced by the Producer. The producers and consumers share the same memory
buffer that is of fixed size.
The job of the Producer is to generate the data, put it into the buffer, and again start generating data. At the same
time, the job of the Consumer is to consume the data from the buffer.
C++ Code:
Output:
P a g e 26 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 2:
Change the buffer size to 5000, make it hard coated i.e. remove the user choices, produce a value in it, and then
consume it, after consuming show that the buffer is empty. If the buffer is empty then create a file named
“your_name” on the desktop using the appropriate systemcall. Attach screenshots of each step and the code.
P a g e 27 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Description:
MFT (Multi-programming with a Fixed number of Tasks) is one of the old memory management techniques in
which the memory is partitioned into fixed-size partitions and each job is assigned to a partition. The memory
assigned to a partition does not change.
ALGORITHM:
Step 1: Start the process.
Step 2: Declare variables.
Step 3: Enter total memory size ms.
Step 4: Allocate memory for os.
Ms=ms-os
Step 5: Read the no partition to be divided n Partition size=ms/n.
Step 6: Read the process no and process size.
Step 7: If the process size is less than the partition size then allots, otherwise block the process. While allocating
Task 1:
You have a memory system with a total capacity of 900 bytes, and the memory is divided into blocks of 250
bytes each. Four processes are scheduled to run, each requiring a different amount of memory. The
memory allocation for each process is as follows:
1. Process 1: Requires 200 bytes
2. Process 2: Requires 250 bytes
3. Process 3: Requires 75 bytes
4. Process 4: Requires 125 bytes
Discuss the output based on the memory allocation for these processes.
Task 1: Simulation
Given:
P a g e 28 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Processes:
Process Memory Required Fits in Partition (250 bytes)? Status External Fragmentation
P1 200 bytes Yes Allocated 250 - 200 = 50 bytes
P2 250 bytes Yes Allocated 250 - 250 = 0 bytes
P3 75 bytes Yes Allocated 250 - 75 = 175 bytes
P4 125 bytes ❌ No partition left Blocked -
Results:
Task 2:
You are tasked with managing a memory system with a total capacity of 3000 bytes, and the memory is
organized into blocks of 500 bytes each. Six processes are scheduled to run, each with varying memory
requirements. The memory allocation for each process is as follows:
1. Process 1: Requires 200 bytes
2. Process 2: Requires 300 bytes
3. Process 3: Requires 1000 bytes
4. Process 4: Requires 120 bytes
5. Process 5: Requires 500 bytes
6. Process 6: Requires 4010 bytes
Discuss the output based on the memory allocation for these processes.
Given:
Processes:
Process Memory Required Fits in Partition (500 bytes)? Status External Fragmentation
P1 200 bytes Yes Allocated 500 - 200 = 300 bytes
P a g e 29 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Process Memory Required Fits in Partition (500 bytes)? Status External Fragmentation
P2 300 bytes Yes Allocated 500 - 300 = 200 bytes
P3 1000 bytes No Blocked -
P4 120 bytes Yes Allocated 500 - 120 = 380 bytes
P5 500 bytes Yes Allocated 500 - 500 = 0 bytes
P6 4010 bytes No Blocked -
Results:
P a g e 30 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Description:
MVT (Multi-programming with a Variable number of Tasks) is the memory management technique in which each
job gets just the amount of memory it needs. That is, the partitioning of memory is dynamic and changes as jobs
enter and leave the system. MVT is a more ``efficient'' user of resources.
MFT suffers from the problem of internal fragmentation and MVT suffers from external fragmentation.
Task 1:
Create a memory of 1000 bytes. Try to run processes with 200 bytes, 300 bytes, 75 bytes, 125 bytes, and 300
bytes respectively. Discuss the output.
Processes:
C++ code:
P a g e 31 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Output:
Task 2:
Create a memory of 3000 bytes. Try to run processes with 200 bytes, 300 bytes, 1000 bytes, 1200 bytes, and
5000 bytes respectively. Discuss the output.
C++ Code:
Output:
P a g e 32 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Lab 13: Single level and two-level directory File Organization Techniques
OBJECTIVE: To write a C program to simulate the following file organization techinques.
a) Single level directory
b) Two level directory
Description:
Single Level Directories:
It is the simplest of all directory structures, in this the directory system having only one directory, it consisting of
all files. Sometimes it is said to be the root directory. The following dig. Shows single level directory that contains
four files (A, B, C, D). It has the simplicity and ability to locate files quickly. It is not used in the multi-user
system; it is used on the small embedded system.
Task 1: Create 3 two level directories using your name, your surname and your nick name respectively. Create 3
files in each directory and display them.
P a g e 33 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Task 2:
Create a one level directory using your name with last 3 digits of your registration number at the end, place 5 files
in it and display.
P a g e 34 | 108