Task of Lab - 01
Task of Lab - 01
Objective:
The objective of this task is to install Ubuntu, a popular open-source Linux distribution, on a
computer or virtual machine. The installation process involves setting up partitions, selecting
installation options, and ensuring that the operating system runs correctly.
Abstraction:
Conclusion:
After completing the installation, you should take screenshots of the different stages, such as:
Objective:
The objective of this lab exercise is to execute a series of common Linux commands to familiarize
yourself with the terminal and the various file management, search, and user administration tasks in
Linux. The goal is to demonstrate how to list files, search directories, display file contents, and
manage user and group-related operations effectively using common Linux commands.
Abstraction:
In this lab exercise, various frequently used Linux commands were executed to perform tasks
related to file management, searching, and user/group administration. The tasks included listing
files in directories, searching for specific files based on patterns, displaying file contents, and
manipulating file attributes. Key commands such as ls, find, cat, grep, and groupadd were
used to handle different operations like listing files, searching for files based on name or
modification time, counting files, and viewing file contents. The exercise also covered user and
group management commands, demonstrating how to create groups, assign users to them, and set
passwords. These operations provide foundational knowledge necessary for managing files,
performing system searches, and administering users in a Linux environment.
● Display the content of the/etc/passwd file with as many lines at a time as the last digit of
your roll number.
● Search the current directory, look for filenames that don’t begin with a capital letter.
● Search the system for files that were modified within the last two days.
Search the system for files that were modified within the last two days:
● List all files in the current directory and their sizes; use multiple columns and mark special
files.
List all files in the current directory and their sizes; use multiple columns and
mark special files:
Objective:
The objective of this lab session was to practice essential Linux commands for managing
files and directories. These commands include creating, modifying, sorting, archiving, and
managing files through various tools. We also aimed to understand file attributes,
checksum verification, file splitting, and the practical use of the tar, cp, and cpio
commands, which are fundamental for file management and system administration in
Linux.
Abstraction:
In this lab session, we practiced using several Linux commands to manage files and
directories. The commands we explored include lockfile, cksum, comm, csplit,
chattr, and touch, each serving distinct purposes related to file manipulation, checksum
calculation, file splitting, and setting file attributes. Additionally, we executed commands
such as cat, cpio, sort, fuser, and file to manage and process files in various ways.
The session also covered understanding the tar command’s -z option and the difference
between the cp and cpio commands, helping us understand how files are copied,
archived, and extracted in Linux. By completing these tasks, we developed practical skills
for efficiently managing files and directories within the Linux environment.
Lockfile: The lockfile command is used to create a lock file, typically for ensuring that only one instance
of a script or process can run at a time. It's useful for preventing race conditions.
Cksum: The cksum command calculates and displays the checksum and byte size of a file. It can be used
to verify file integrity.
Comm: The comm command is used to compare two sorted files line by line. It outputs three
columns: lines only in the first file, lines only in the second file, and lines common to both files.
Csplit: The csplit command splits a file into multiple files based on context patterns or specific
line numbers.
Chattr: The chattr command is used to change file attributes on a Linux file system. It can be
used to make files immutable (cannot be modified or deleted).
Touch: The touch command is used to create an empty file or to update the access and modification times
of an existing file.
EXECUTE FOLLOWING COMMANDS?
echo: Displays a line of text or a variable value to the terminal, commonly used for printing
messages or setting variables.
fuser: Identifies processes using a specified file or socket, and can kill those processes.
file: Determines and displays the file type based on its content, not just the file
extension.
sort: Sorts lines of text files or input based on various criteria such as alphabetical,
numerical, or reverse order.
What does the z option of the tar command do? Explain with examples.
The -z option of the tar command is used to compress the archive using gzip
compression.
Explanation:
● The -z option tells tar to compress the archive it creates or extracts using the gzip
utility, which reduces the size of the archive by compressing it.
Examples:
○ Explanation:
■ -c creates a new archive.
■ -z compresses it using gzip.
■ -f specifies the filename of the archive.
○ This creates a gzip-compressed archive called archive.tar.gz containing
the contents of the directory/.
2. Extracting from a Compressed Archive with tar -z:
○ To extract a .tar.gz file:
tar -xzf archive.tar.gz
○ Explanation:
■ -x extracts the archive.
■ -z decompresses it using gzip.
■ -f specifies the archive filename (archive.tar.gz).
○ This will extract the contents of archive.tar.gz to the current directory.
1. cp Command:
○ The cp command is used to copy individual files and directories from one
location to another.
○ It is a simple command that handles copying of files or directories without
involving any archiving or compression.
○ Usage: Typically used for basic copying tasks like copying a file from one
directory to another.
○
2. cpio Command:
○ The cpio command is used for copying files into or out of archives. It is
typically used for bulk copying or creating backups.
○ cpio reads and writes files in archive formats, which can include
compressed files.
○ Usage: Commonly used for archiving multiple files or directories at once or
○
○ Feature: It is especially useful for backups and restoring files, and can
handle file lists or directories as input
Objective:
The objective of this shell program is to demonstrate the process of writing a script that multiplies
two numbers and calculates the average of three numbers in a Linux environment. This exercise
helps in understanding basic shell scripting concepts, including user input, arithmetic operations,
and output.
Abstraction:
Multiplication 2 numbers
Average of three numbers
Conclusion:
In this exercise, we successfully created two shell programs: one to multiply two numbers
and another to calculate the average of three numbers. The programs demonstrate basic
shell scripting concepts, such as reading user input, performing arithmetic operations, and
displaying the output. This helps in building a foundation for more complex shell scripting
tasks, such as data processing and automation in Linux environments.
TASK OF LAB: 05
To Execute shell scripting for finding large numbers and factorial of numbers.
Objective:
1. A script that takes a number (1-3) as input and uses the case statement to display the
corresponding month name.
2. A script that defines a function which takes a number (1-7) as input and displays the
corresponding day of the week starting from Sunday. If the number provided is outside the
valid range, an error message is displayed.
Abstraction:
-Make a script that takes a number (parameter) from 1-3 as input and uses the case
to display the name of the corresponding month.
-Make a function that displays the name of the week days starting from Sunday if the
user passes a day number. If a number provided is not between 1 and 7 an error
message is displayed.
conclusion:
1. A script that uses the case statement to display the month name corresponding to
a given number between 1 and 3.
2. A function that displays the day of the week starting from Sunday based on a given
number between 1 and 7.
These exercises helped demonstrate the use of the case statement in shell scripting,
which is useful for handling multiple conditions based on user input.
TASK OF LAB: 06
Using conditional, branching and looping MAKE statements in shell scripting
Objective:
1. Create a script that compares two strings provided by the user and prints a message based
on the result of the comparison (e.g., whether they are equal, one is greater, or one is
smaller).
2. Create a script that backs up each file in the user's home directory to a subdirectory called
backup using a for loop. If the backup operation fails, the script should display an error
message.
Abstraction:
-Make a script that takes two strings as input compares them and depending upon the
results of the comparison prints the results.
Make a script that creates a backup version of each file in your home directory toa
subdirectory called backup using for statement. If the operation fails an error messageis to
be displayed.
Conclusion:
1. The first script compared two strings and printed the result of the comparison,
demonstrating the use of conditional statements in shell scripting.
2. The second script used a for loop to back up each file in the user's home directory to a
backup subdirectory, checking for success or failure of each file backup.
Open-Ended Lab - 01
Perform the below-mentioned exercises of shell scripting and show its
output as well.
Objective:
1. Create a script that compares two strings provided by the user and prints a message based
on the result of the comparison (e.g., whether they are equal, one is greater, or one is
smaller).
2. Create a script that backs up each file in the user's home directory to a subdirectory called
backup using a for loop. If the backup operation fails, the script should display an error
message.
Abstraction:
Tasks
● Make a shell script that prints “Shell Scripting is Fun!” on the screen.
● Modify the shell script from exercise 1 to include a variable. The variable
will hold the contents of the message “Shell Scripting is Fun!”
Conclusion:
In this lab exercise, we successfully created and tested three shell scripts:
These exercises helped develop the understanding of basic shell scripting concepts such
as text printing, using variables, and capturing the output of commands. This knowledge is
fundamental for automating tasks and working effectively in a shell environment.
TASK OF LAB: 08
Demonstrate CPU Scheduling Algorithms FCFS Using GCC Compiler In Linux.
Objective:
The objective of this lab task is to simulate the First Come First Serve (FCFS) processor
scheduling algorithm in C. This task will allow students to:
1. Understand how process scheduling works and how different scheduling algorithms impact
process execution.
2. Learn how to implement FCFS scheduling with additional considerations such as process
priorities and sorting by priority.
3. Compute the waiting time, turnaround time, and average waiting/turnaround time for
processes.
4. Display the Gantt chart to visually represent the execution of processes.
Abstraction:
Conclusion:
This program demonstrates how the FCFS Scheduling Algorithm works, including sorting
processes by priority, calculating waiting and turnaround times, and displaying a Gantt chart for
process execution. You can easily run this code on any online compiler by following the above
steps.
TASK OF LAB: 09
Try implementation of SJF scheduling algorithm using c programming
Objective:
The goal of this lab task is to simulate the Shortest Job First (SJF) CPU Scheduling Algorithm in
C. This algorithm schedules jobs based on the shortest burst time, meaning that the process with
the smallest burst time is given priority to execute first. The task requires calculating the waiting
time, turnaround time, and displaying the Gantt chart for the processes involved. This exercise
aims to help in understanding how CPU scheduling works, especially when the burst time of each
process is known in advance.
Abstraction:
The Shortest Job First (SJF) Scheduling algorithm selects the process with the smallest burst time
to execute first. This algorithm is optimal in terms of minimizing the average waiting time, but it
requires knowing the burst time of each process beforehand. This simulation involves the following
steps:
1. Input the number of processes and their respective burst times.
2. Sort the processes based on burst time in ascending order.
3. Calculate the waiting time and turnaround time for each process.
4. Display the Gantt chart, which visually shows the sequence of execution.
5. Compute average waiting time and average turnaround time.
Code:
Explanation of the Code:
1. Structure Definition (struct process): This structure stores the process ID, burst time,
waiting time, and turnaround time for each process.
2. Sorting by Burst Time: The sort_processes() function sorts the processes in
ascending order based on their burst times to simulate the SJF algorithm.
3. Calculating Waiting Time and Turnaround Time: The calculate_times() function
calculates the waiting time and turnaround time for each process. The first process has a
waiting time of 0, and subsequent processes have their waiting times calculated based on
the burst times of previous processes.
4. Displaying Results: After calculating the necessary times, the program displays the
process details and the average waiting time and turnaround time.
5. Displaying Gantt Chart: The Gantt chart is displayed to visualize the execution sequence
of processes.
OUTPUT:
Conclusion:
The Shortest Job First (SJF) Scheduling algorithm is an efficient scheduling algorithm that
minimizes the average waiting time, especially when the burst time of each process is known
beforehand. This simulation in C demonstrates how to apply SJF scheduling by sorting processes
based on burst times, calculating the necessary times, and displaying the results in a Gantt chart.
The program successfully computes the average waiting time and turnaround time, helping to
understand the theoretical concepts in CPU scheduling.
TASK OF LAB: 10
Try implementation of Priority scheduling algorithms (primitive and non-
primitive).
Objective
The objective of this lab task is to simulate the First Come First Serve (FCFS) Processor
Scheduling Algorithm while incorporating Priority Scheduling. The goal is to:
Abstraction
This lab task simulates the FCFS scheduling algorithm with priority scheduling in C. The user is
asked to input the number of processes, burst times, and priorities of processes. The program
calculates waiting times and turnaround times for each process and displays the results. It also
calculates the average waiting and turnaround times, followed by a Gantt chart to visualize the
execution order of the processes. This simulation helps in understanding the CPU scheduling
process, its performance metrics, and how scheduling algorithms like FCFS affect overall system
performance.
1. Input: The program accepts the number of processes and for each process, it asks for the
burst time and priority.
2. Sorting: The processes are sorted based on their priority. If two processes have the same
priority, FCFS is applied to resolve the tie.
3. Calculation: The waiting time for the first process is 0. Then, for each process, the waiting
time is calculated as the sum of the burst times of all previous processes. The turnaround
time for each process is calculated as the sum of its burst time and waiting time.
4. Average Calculation: The average waiting time and turnaround time are calculated and
displayed.
5. Gantt Chart: The Gantt chart is displayed showing the processes in the order they are
executed along with their respective times
C Code for FCFS Scheduling with Priority
Here is the C program that simulates the First Come First Serve (FCFS) scheduling with Priority
output:
Conclusion:
This program simulates the FCFS (First Come First Serve) processor scheduling algorithm
using priority scheduling. The processes are first sorted by priority, and then FCFS is
applied to resolve ties. The program calculates the waiting time and turnaround time for
each process, and displays the results, including the average waiting time and average
turnaround time. Additionally, the program displays the Gantt chart to help visualize the
execution order of processes. This simulation demonstrates the importance of scheduling
algorithms in operating systems to optimize resource utilization and process management.
TASK OF LAB: 11
Execute C Program To Implement Round Robin Scheduling
Objective
The objective of this lab task is to simulate the Round Robin (RR) Processor Scheduling
Algorithm in C. Round Robin is a preemptive scheduling algorithm in which each process is
assigned a fixed time slice (quantum) in a cyclic order. The task is to:
Abstraction
In Round Robin scheduling, the CPU scheduler assigns a fixed time slice or quantum to each
process in a cyclic order. If a process does not complete its execution within its time quantum, it is
placed back in the ready queue, and the next process gets its turn. This is done until all processes
are finished. The program calculates and displays the waiting time and turnaround time for each
process, as well as their averages. The Gantt chart is displayed to help visualize the order of
process execution.
This task helps in understanding the Round Robin scheduling algorithm's application in process
management and how it is used to ensure fairness in CPU allocation.
1. Input:
○ The user is asked to input the number of processes.
○ Then, for each process, the burst time is provided.
○ Finally, the user enters the time quantum (fixed time slice).
2. Round Robin Scheduling:
○ The algorithm simulates the Round Robin scheduling by assigning a fixed time
quantum to each process.
○ If a process doesn't finish in one time slice, it is preempted and placed back in the
queue.
○ The remaining time for each process is updated after every cycle.
3. Waiting Time and Turnaround Time:
○ After the processes complete execution, the waiting time and turnaround time for
each process are calculated.
○ The average waiting time and average turnaround time are displayed.
4. Output:
○ The program outputs the waiting time and turnaround time for each process, the
average waiting time, and the average turnaround time.
Conclusion
This program simulates the Round Robin (RR) CPU scheduling algorithm. The algorithm
ensures fairness by providing each process a fixed time slice (quantum) and executing
them in a cyclic order. The program calculates the waiting time and turnaround time for
each process, as well as the average waiting time and average turnaround time for the
entire system. Additionally, it displays the Gantt chart that helps visualize the execution of
processes.
This exercise helps understand how Round Robin scheduling works and how it impacts
the performance of the system, specifically in terms of average waiting time and average
turnaround time. The task also reinforces key concepts related to process scheduling in
operating systems.
TASK OF LAB: 12
Execute C Program To Implement Bankers Algorithm For Deadlock Avoidance.
Objective
The objective of this lab task is to simulate the Banker's Algorithm for resource allocation and
deadlock avoidance in an operating system. The Banker's Algorithm checks whether the system is
in a safe state or not by ensuring that there are enough resources available to allow all processes
to complete without causing a deadlock. The system is said to be in a safe state if there exists a
sequence of processes that can be executed without exceeding the available resources. If the
system is in an unsafe state, deadlock might occur.
Abstraction
The Banker's Algorithm works by keeping track of the resources allocated to each process and the
remaining resources needed for each process to finish its execution. It uses the following steps:
1. Inputs: The number of processes, number of resources, available resources, and the
resources allocated to each process.
2. Safety Check: The algorithm calculates whether the system can safely execute all
processes without running into a deadlock. It does this by checking if there is a sequence of
processes that can be completed with the available resources.
3. Output: If the system is in a safe state, the Banker's Algorithm will display the sequence in
which processes will be executed. If the system is in an unsafe state, it will indicate that a
deadlock might occur.
C Code for Banker's Algorithm
1. Input:
○ Number of processes (n) and number of resources (m).
○ Allocated resources matrix: Each process's allocated resources.
○ Maximum resources matrix: The maximum resources each process may need.
○ Available resources vector: The number of available resources in the system.
2. isSafe Function:
○ It checks whether the system is in a safe state or not by attempting to find a
sequence of processes that can complete using available resources.
○ It loops through all processes and tries to execute those that can finish based on the
current available resources.
○ If a process can finish, its allocated resources are added back to the available
resources, and the process is marked as finished.
○ If all processes can finish in a valid order, the system is in a safe state.
3. Output:
○ The program outputs whether the system is in a safe state or unsafe state.
○ If in a safe state, the safe sequence of process execution is displayed.
Conclusion
This program simulates the Banker's Algorithm for deadlock avoidance and resource allocation in
an operating system. By checking whether the system is in a safe state or not, the Banker's
Algorithm ensures that resources are allocated in such a way that no deadlock will occur. The
algorithm calculates whether a safe sequence of processes exists, which can be executed without
exhausting the available resources.
This task provides an understanding of how operating systems manage resources and prevent
deadlock by using algorithms like the Banker's Algorithm. By simulating this, students can learn
how resource allocation works in a concurrent system and the importance of maintaining a safe
state.
TASK OF LAB: 13
Execute C program to implement algorithm for deadlock detection.
Objective
The objective of this lab task is to implement an algorithm for Deadlock Detection in
an operating system. The program will simulate a system where multiple processes
request and release resources. The algorithm will detect if there is a deadlock in the
system by evaluating the resource allocation matrix, maximum resources matrix,
and available resources. The deadlock detection algorithm will ensure that
processes either complete their execution or remain in a deadlock state.
Abstraction
1. Input: The program takes the number of processes, number of resources,
resource allocation matrix, maximum resource matrix, and available resource
vector as input.
2. Matrix Calculation: The program calculates the need matrix by subtracting
the allocation matrix from the maximum matrix for each process.
3. Deadlock Detection: The algorithm checks whether each process can finish
by comparing its need matrix with the available resources. If all processes
can finish, there is no deadlock; if not, the system is in a deadlock state.
4. Output: The system will display the processes involved in the deadlock (if
any), otherwise indicate that there is no deadlock.
Conclusion
Objective
Abstraction
In multi-threaded programs, threads run concurrently, allowing efficient CPU utilization. However,
without synchronization, threads can interfere with each other, leading to race conditions and
incorrect results. To solve these issues, synchronization mechanisms like mutexes, semaphores,
or condition variables are used.
This program demonstrates basic threading, synchronization, and error checking in C using the
POSIX threads library (pthread).
output
Conclusion
This program successfully demonstrates basic threading and synchronization using POSIX
threads (pthreads) in C. The synchronization is achieved through the use of a mutex to ensure that
threads do not interfere with each other in critical sections. Proper error handling is implemented to
check for thread creation and joining failures. This approach helps in managing concurrent threads
in a multi-threaded environment while preventing race conditions.