Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views29 pages

Adbullah Ismail F078 CS B

The document is a lab manual for the Operating Systems course at the School of Computer and Information Technology, detailing various lab exercises focused on Linux OS, process management, system calls, and scheduling algorithms. Each lab includes objectives, tasks, and mapping to course learning outcomes. The manual serves as a comprehensive guide for students to gain practical experience with Linux commands and programming in C.

Uploaded by

saadshakir2300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views29 pages

Adbullah Ismail F078 CS B

The document is a lab manual for the Operating Systems course at the School of Computer and Information Technology, detailing various lab exercises focused on Linux OS, process management, system calls, and scheduling algorithms. Each lab includes objectives, tasks, and mapping to course learning outcomes. The manual serves as a comprehensive guide for students to gain practical experience with Linux commands and programming in C.

Uploaded by

saadshakir2300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Operating System Lab Report

Submitted To:
Prof. Naveed Akhtar
Submitted By:
Abdullah Ismail
Student ID:
2023-CS-F078
Email ID:
[email protected]
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:

Lab1: Familiarizing with the Linux Operating System Environment and


Terminal`
Lab 2: Exploring the use of different Linux commands to use the OS through
the terminal
Lab 3: Implementation of UNIX Streams, Pipes and Redirects in Linux
terminal
Lab 4: Process Management in Linux systems
Lab 5: Open Ended
Lab 6: Installation of C compiler and Vim editor in Linux.
Lab 7: Implementation of System calls in Linux using C language
Lab 8: Implementation of Process Scheduling Algorithms FCFS and SJF
Lab 9: Implementation of Process Scheduling Algorithms ROUND ROBIN and
PRIORITY (Open Ended)
Lab 10: Simulate Producer-Consumer Problem using Semaphores
Lab 11: Memory Management with Fixed Partitioning Technique (Open-
Ended)
Lab 12: Memory Management with Variable Partitioning Technique
Lab 13: Single level and two-level directory File Organization Techniques

P a g e 2 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Lab1: Familiarizing with the Linux Operating System Environment and


Terminal
`
Lab Objective: To introduce students to the Linux Environment and usage of Linux terminal.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1:
When you open the terminal, what directory are you in by default? Use appropriate command to print it.
Steps:

 Open the terminal.


 Type the following command to display the current working directory:
 The output will typically show something like /home/username, which is your home directory.

Task 2:

Go to /etc./apt directory and display the list of contents using appropriate commands

Step:

 Open Terminal in Ubuntu.

P a g e 3 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
 Change directory to /etc/apt:

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
the root directory.

P a g e 4 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Question 1: What is the difference between absolute and relative path?

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.

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.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1:
Locate a file named passwd using the appropriate command.

P a g e 5 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

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.

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

P a g e 6 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

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”.

Lab 3:
Implementation of UNIX Streams, Pipes and Redirects in Linux terminal
Lab Objective: To introduce students with different Linux commands to control the OS through terminal.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

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.

P a g e 7 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

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.

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.

P a g e 8 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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.

Lab 4: Process Management in Linux systems


Lab Objective:
To learn how processes are managed in Linux Operating systems.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1: Start a few programs in your desktop. Then use ps to identify their PID and kill them.

P a g e 9 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Lab 5: Open Ended


Lab Objective:
To test students how good they are with Linux basic commands.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

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.

P a g e 10 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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

Screenshot 2:

The ps aux command lists all system processes with details such as:

 User
 PID
P a g e 11 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
 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 12 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Lab 6: Installation of C compiler and Vim editor in Linux.


Objective:
 Learn to install the C compiler and Vim editor using Linux-appropriate commands
 Learn how to write and compile code in Linux.

 MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

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.
P a g e 13 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Update the Package List:

sudo apt update

Install the GCC Compiler

sudo apt install gcc

Install the G++ Compiler

sudo apt install g++

Verification of Installation

gcc –version

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.

1. Installing Vim on Linux:

sudo apt install vim


P a g e 14 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

2. Verifying the Installation

vim –version

Compile the Following C code.

Lab 7: Implementation of System calls in Linux using C language


Objective: Implementation of System calls by executing C-programs

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.
P a g e 15 | 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 16 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Task3: Implement Exec system call on your Linux system.

Lab 8: Implementation of Process Scheduling Algorithms FCFS and SJF


OBJECTIVE: To write a program to stimulate the CPU scheduling algorithm FCFS and SJF

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1:
P a g e 17 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Run the C++ code for FCFS with arrival time and explain the process and the output in detail.

FCFS CPU Scheduling in C++:

Explanation of Process and Output:

Input Section:

 You enter the number of processes.


 For each process, input its arrival time and burst time.

Sorting:

 The processes are sorted based on their arrival time to simulate the FCFS order.

Calculation:

 For each process, the program calculates:


o Start Time (ST): When the process starts.
o Completion Time (CT): When the process finishes.
o Turnaround Time (TAT): CT - Arrival Time.
o Waiting Time (WT): TAT - Burst Time.

Output Table:

P a g e 18 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

Averages:

 Calculates average waiting time and turnaround time.

Task 2:
Write the C/C++ program for SJF following the algorithm given and discuss the process and output.

Explanation of the Process


Input:

 The user inputs the number of processes and their burst times.
P a g e 19 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
Calculation:

 Waiting Time (WT) for the first process is 0.


 The next process waits for the burst time of all previous processes.
 Turnaround Time (TAT) is calculated by:
TAT = WT + BT.

Output:

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.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1:

Run the C code for Round Robin and explain the process and the output in detail.
P a g e 20 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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.

 Time Quantum: Fixed time a process can use the CPU.


 Preemptive: If a process isn’t finished in its time slice, it's paused and other processes get a turn.

C++ code:

Output:

Task 2:
Write the C program for PRIORITY following the algorithm given above and discuss the process and output.
P a g e 21 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY

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:

Output:

Lab 10: Simulate Producer-Consumer Problem using Semaphores


P a g e 22 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
OBJECTIVE: Writing a C program to simulate a Producer-Consumer Problem using Semaphores.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes, and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

C++ Code:

Output:

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
P a g e 23 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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.

Lab 11: Memory Management with Fixed Partitioning Technique (Open-


Ended)
OBJECTIVE: To implement and simulate the MFT algorithm.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

Task 1:

You have a memory system with a total capacity of 900 bytes, and the memory is divided into blocks of 250
P a g e 24 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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:

 Total memory size = 900 bytes


 Partition size = 250 bytes
 Number of partitions = 900 ÷ 250 = 3 partitions
 OS memory size isn't mentioned, so we assume it's already excluded or negligible.

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:

 Processes allocated: 3 (P1, P2, P3)


 Process blocked: 1 (P4)
 Total memory used: 200 + 250 + 75 = 525 bytes
 Total internal fragmentation: 50 + 0 + 175 = 225 bytes
 Unused memory due to lack of partitions: 900 - (3×250) = 0 (none wasted this way)

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

P a g e 25 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
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:

 Total memory size = 3000 bytes


 Partition size = 500 bytes
 Number of partitions = 3000 ÷ 500 = 6 partitions

Processes:
Process Memory Required Fits in Partition (500 bytes)? Status External Fragmentation
P1 200 bytes Yes Allocated 500 - 200 = 300 bytes
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:

 Processes allocated: 4 (P1, P2, P4, P5)


 Processes blocked: 2 (P3, P6)
 Total internal fragmentation: 300 + 200 + 380 + 0 = 880 bytes
 Total memory used by allocated processes: 200 + 300 + 120 + 500 = 1120 bytes
 Unused memory partitions: 2 partitions remain unused

Lab 12: Memory Management with Variable Partitioning Technique

P a g e 26 | 108
LAB MANUAL SCHOOL OF COMPUTER AND INFORMATION TECHNOLOGY
OBJECTIVE: To implement and simulate the MVT algorithm.

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Use Linux to implement system programs related to
process synchronization, shared memory, mailboxes and file PLO 5: Modern Tool Usage
Psychomotor Domain: P3
systems.

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.

Initial Memory: 1000 bytes

Processes:

 P1: 200 → Allocated → Remaining: 800


 P2: 300 → Allocated → Remaining: 500
 P3: 75 → Allocated → Remaining: 425
 P4: 125 → Allocated → Remaining: 300
 P5: 300 → Allocated → Remaining: 0

C++ code:

P a g e 27 | 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 28 | 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

Create 3 directories named with your name, surname, and nickname

Create 3 files inside each directory

Display the contents of each directory

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 29 | 108

You might also like