SLEUVA_os[1]
SLEUVA_os[1]
B.E. Semester-IV
(Information Technology)
240163116010
Government Engineering College, Modasa
Certificate
Place:
Date:
240163116010
Operating System and Virtualizations (3141601)
240163116010
14. Shell programming using filters (including grep, egrep, √
fgrep)
240163116010
Operating System and Virtualizations (3141601)
16. Write a shell script to validate the entered date. (eg. Date √
format is : dd-mm-yyyy).
Write an awk program using function, which convert each
17. √
word in a given text into capital
Write a program for process creation using C. (Use of gcc
18. √
compiler)
240163116010
Operating System and Virtualizations (3141601)
Index
240163116010
Write a shell script to validate the entered date. (eg.
16.
Date format is: dd-mm-yyyy).
240163116010
Operating System and Virtualizations (3141601)
240163116010
Experiment No: 1
Aim: Study of Linux operating system, its variants and installation of Linux
Operating system
Date:
Relevant CO: Learn and understand the concepts, core structure of Operating Systems
and basic architectural components involved in operating systems design
Objectives:
To understand the foundational concepts of the Linux operating system.
To recognize and differentiate between various Linux distributions.
To gain hands-on experience in the installation process of Linux as the primary
OS.
Theory:
The Linux operating system is an open-source OS based on the UNIX architecture. It
was developed by Linus Torvalds in the early 1990s. The core of Linux, called the kernel,
interacts directly with the system hardware and provides services to the software
applications.
Linux is known for its flexibility, security, and adaptability. Over time, several
distributions (or 'distros') have evolved, each designed for specific use-cases. Some popular
Linux distributions include Ubuntu, Fedora, Delian, CentOS, and Red Hat.
Installation:
Procedure:
1. Select a Linux distribution: For beginners, Ubuntu or Fedora is often recommended due
to their user-friendly interfaces.
2. Download the ISO File: Go to the official website of your chosen distribution and
download the ISO file.
3. Create a Bootable Media: Use tools like 'Rufus' or 'UNetbootin' to create a bootable USB.
4. Insert the Bootable Media: Plug the USB drive into the computer you want to install
Linux on.
5. Reboot & Select Boot Media: Reboot the computer. During the startup, press the
boot menu key (usually F2, F10, or F12) and select the USB drive.
240163116010
6. Follow Installation Instructions: Once booted from the USB, you'll be guided through
various steps like partitioning the hard drive, setting the time zone, and creating a user
account.
7. Finish Installation: After all steps, Linux will be installed. Reboot the computer, and you
should boot into your new Linux OS.
Observations:
Step-1: Select a Linux distribution: we are using Ubuntu Linux System.
240163116010
Step-3: Create/Insert a Bootable Media:
240163116010
Step-5: Follow Installation Instructions:
1.
2.
240163116010
2.
Quiz:
1. Who developed the Linux operating system?
Answer: The Linux operating system was developed by Linus Torvalds in 1991.
4. Why do we need to create a bootable USB or DVD for the installation of Linux?
Answer: Creating a bootable USB or DVD is necessary for Linux installation because it
allows the computer to boot from the external media and initiate the installation process
without needing an already functioning operating system on the computer's hard drive.
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 2
Date:
Relevant CO: Learn and understand the concepts, core structure of Operating Systems
and basic architectural components involved in operating systems design
Objectives:
To comprehend the principle of virtualization and its significance in modern
computing.
To differentiate between Host and Guest operating systems.
To master the process of setting up virtualization software on Windows.
To successfully install and run Linux as a guest OS inside a virtualized
environment.
Theory:
Virtualization refers to the act of creating a virtual version of something, including
but not limited to a virtual computer hardware platform, operating system (OS), storage
device, or network resources. By using virtualization software, one can run multiple
operating systems on a single physical computer. In this context, the system on which you're
running the virtualization software (Windows in this case) is known as the Host OS, and the
OS you're installing inside the virtualized environment is called the Guest OS.
One popular virtualization software is Virtual Box, which allows users to create and
manage virtual machines. These virtual machines can run various operating systems,
providing a sandboxed environment that operates independently of the host system.
Procedure:
1. Download & Install Virtualization Software: Download Oracle Virtual Box (or any
other preferred virtualization software) from its official website and install it on your
Windows OS.
2. Download Linux ISO File: Go to the official website of your chosen Linux distribution
and download the ISO file.
240163116010
5. Attach the Linux ISO:
- With the VM highlighted, click on 'Settings'.
- Go to 'Storage', click on the empty disk icon under the IDE controller, and on the right
side, click on the disk icon to choose a virtual optical disk file. Select the downloaded Linux
ISO.
6. Start the Virtual Machine: Click 'Start' on Virtual Box to run the VM. The Linux installer
should boot up.
8. Install Guest Additions: After installation, for better performance and integration
features, it's recommended to install Virtual Box Guest Additions.
Observations:
Step-1: Download & Install Virtualization Software:
240163116010
Step-3: Launch Virtual Box and Create New VM:
1.
2.
240163116010
Step-4: Set Up Virtual Hard Disk:
1.
2.
240163116010
Step-6: Start the Virtual Machine:
240163116010
Step-8: Install Guest Additions: After installation, for better performance and integration
features, it's recommended to install Virtual Box Guest Additions.
Result:
1. Virtualization software was installed and configured on the Windows host system.
2. Linux was successfully installed as a guest OS within the virtualized environment.
3. Basic operations within the Linux guest OS were performed, demonstrating its isolated nature.
Conclusion:
The successful installation of Linux as a guest OS on Windows using virtualization software
highlights the importance and practical application of virtualization in modern computing.
Participants gained valuable hands-on experience in setting up and managing virtualized
environments, enhancing their understanding of operating system concepts and architecture. This
exercise provided a solid foundation for further exploration and utilization of virtualization
technology in various computing scenarios.
Quiz:
1. What is the difference between a Host OS and a Guest OS in virtualization?
Answer: The Host OS (Operating System) is the main operating system installed
directly on the physical hardware of a computer, while the Guest OS is an
operating system running within a virtual machine (VM) on the Host OS.
2. Name one popular virtualization software used to run multiple operating systems
on a single machine.
Answer: One popular virtualization software used to run multiple operating
systems on a single machine is VMware.
240163116010
3. Why is it recommended to install Guest Additions in Virtual Box after installing a
Linux guest OS?
Answer: It is recommended to install Guest Additions in VirtualBox after
installing a Linux guest OS because Guest Additions enhance the performance and
usability of the virtual machine by providing features such as better display
resolution, mouse integration, and improved file sharing between the guest and
host operating systems.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 3
Date:
Relevant CO: Learn and understand the concepts, core structure of Operating Systems
and basic architectural components involved in operating systems design
Objectives:
To familiarize students with the fundamental concepts of the Linux/UNIX command line.
To learn and practice essential file and directory management commands.
To understand process management at a basic level using command-line tools.
To leverage the built-in manual system to gain insights into various commands.
Theory:
Linux/UNIX commands are textual instructions given by users to interact with the operating
system. These commands can perform various tasks such as file management, process
management, hardware status, and more. The place where users input these commands is
typically referred to as the shell, and the most common shell used is called bash (Bourne
Again SHell).
Procedure:
1. Accessing the Terminal: On most Linux systems, you can open the terminal by pressing
Ctrl + Alt + T. On UNIX-based systems or other Linux desktop environments, the terminal
might be found in the application menu.
2. Basic Commands:
- pwd: Prints the current working directory.
- ls: Lists the contents of the current directory.
- cd [directory_name]: Changes the directory to the specified one.
- touch [filename]: Creates a new empty file.
- mkdir [directory_name]: Creates a new directory.
- rm [filename]: Deletes a file.
- rmdir [directory_name]: Deletes an empty directory.
- cp [source] [destination]: Copies files or directories.
- mv [source] [destination]: Moves or renames files or directories.
- echo [text]: Displays a message or output to the screen.
- man [command_name]: Shows the manual page for the specified command.
- ps: Lists currently running processes.
- kill [process_id]: Kills a running process.
240163116010
3. Practice: It's essential to practice these commands to get a feel for how they work. Start
by navigating through directories, creating files, and viewing processes.
Observations:
Syntax: pwd
Output:
Syntax: ls
Output:
Syntax: cd
Output:
Syntax: touch
Output:
Output:
240163116010
· rm :- delete files
Syntax: rm
Output:
Output:
Output:
Output:
Output:
240163116010
· ps :- Display the processes in terminal
Syntax: ps
Output:
Result: Through the experiment, proficiency in essential Linux/UNIX commands such as ls,
cd, mkdir, rm, mv , cp And echo was achieved, demonstrating foundational competence in
navigating the command line interface and performing basic file management tasks.
Conclusion: Using ‘mkdir ‘ , ‘touch’ , ‘rm’ ,’rmkdir’ , ‘cp’ , ‘mv’ command , we can successfully
demonstrate file management task . Using ‘ls’ command we can display list of File in
Directory. Using ‘pwd’ command display the path of current directory.
Quiz:
1. What is the purpose of the Pwd command in Linux/UNIX?
Answer: The purpose of the ‘pwd’ command in Linux/UNIX is to print the current
working directory.
2. How can you view the manual or help page of a particular command?
Answer: You can view the manual or help page of a particular command by using
the ‘man’ command followed by the command name. For example, to view the
manual for the ‘ls’ command, you would type ‘man ls’.
3. Which command is used to list all the running processes in the system?
Answer: The command used to list all the running processes in the system is ‘ps’.
4. How would you create a new directory named "Documents" using a command?
Answer: To create a new directory named "Documents" using a command, you
would use the ‘mkdir’ command followed by the directory name. So, the
command would be ‘mkdir Documents’.
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 4
Date:
Relevant CO:Learn and understand the concepts, core structure of Operating Systems
and basic architectural components involved in operating systems design
Objectives:
1. To delve deeper into the capabilities of the Linux/UNIX command line beyond basic
operations.
2. To understand and master the use of advanced file and text manipulation commands.
3. To explore and utilize filters for processing text streams and files efficiently.
4. To learn the intricacies of combining multiple commands using pipes (|) for enhanced
functionality.
5. To practice and apply advanced commands and filters in real-world scenarios to optimize
tasks and processes.
Theory:
While basic Linux/UNIX commands help in daily tasks, advanced commands and filters
facilitate complex tasks, text processing, and efficient system management. Filters in
UNIX/Linux allow for data manipulation directly from the command line, which can be very
powerful when combined with other commands using pipes (|).
Procedure:
2. Using grep: To search for the word "example" in a file named "sample.txt", use grep
"example" sample.txt.
3. Text Manipulation with awk: For example, to print the second column of a file separated
by commas, you'd use awk -F',' '{print $2}' filename.
240163116010
4. Editing Streams with sed: To replace all occurrences of "apple" with "orange" in a file:
sed 's/apple/orange/g' filename.
6. Extracting Data with cut: To get the third column of a comma-separated file: cut -d',' -f3
filename.
7. Using find: To locate all .txt files in the current directory and its subdirectories: find . -
name "*.txt".
8. Practice: Combining commands using pipes can achieve complex tasks. For instance, to
count unique lines in a file: sort filename | uniq | wc -l.
Observations:
Code:
cat sample.txt | grep Linux
Output:
Code:
Output:
Code:
sed 's/apple/orange/g' sample.txt
Output:
240163116010
· sort: Sorts the contents of a text file line by line.
Code:
sort sample.txt
Output:
Code:
cut -d',' -f3 sample.txt
Output:
Code:
find . -name “*.txt”
Output:
Conclusion: Using ‘grep ‘ , ‘awk’ , ‘sed’ ,’sort’ , ‘cut’ command , we can manipulating Output
of “.txt” File. Using ‘find’ command we can display list File with match condition of file
extension.
Quiz:
1. How would you use grep to search for the word "apple" in a file named "fruits.txt"?
Answer: grep "apple" fruits.txt
240163116010
3. How can the sort and uniq commands be combined to count the number of unique
lines in a file?
Answer: `sort file.txt | uniq -c` combines `sort` to sort lines and `uniq -c` to count
unique lines.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 5
Aim: Write a shell script to generate the mark sheet of a student. Take three
subjects, calculate and display total marks, percentage, and class obtained by
the student.
Date:
Relevant CO: Understand the process management policies and scheduling of processes by
CPU.
Objectives:
1. To familiarize students with the logical flow and structuring of algorithms.
2. To help students comprehend the sequential steps involved in mark sheet generation.
3. To encourage students to think critically and develop their script based on the provided
algorithm.
4. To instill a deep understanding of the relationship between user inputs, processing, and
outputs in scripting.
Theory: A shell script is a sequence of commands for a Unix-based operating system. It's a
text file that contains a series of shell commands and is a way to automate repetitive tasks.
For the given task, we will utilize the shell script's capability to gather inputs, process the
data, and display outputs, focusing on the logic behind generating a student's mark sheet.
Procedure:
1. Initialize:
- Begin the script.
- Declare variables for three subjects, total marks, percentage, and class.
2. Input Marks:
- Prompt the user to enter marks for the first subject and store in the respective variable.
- Prompt for the second subject and store.
- Prompt for the third subject and store.
4. Determine Class:
- If the percentage is 75% or above, assign "Distinction" to the class variable.
- If the percentage is between 60% and 74%, assign "First Class".
- If the percentage is between 40% and 59%, assign "Second Class".
- Otherwise, assign "Fail".
240163116010
5. Display Results:
- Print the total marks out of 300.
- Display the calculated percentage.
- Show the class obtained by the student.
Observations:
Code:
if [ $per -ge 75 ]
then
grade="Distinction"
elif [[ $per -lt 75 && $per -ge 60 ]]
then
grade="First Class"
elif [[ $per -lt 60 && $per -ge 40 ]]
then
grade="Second Class"
else
grade="Fail"
fi
Output:
Result: Upon running the shell script mark_sheet.sh and providing the marks for three
subjects as input, the script calculates the total marks, percentage, and determines the class
obtained by the student.
240163116010
Conclusion:
The shell script successfully performs the following tasks:
o Input Collection: It prompts the user to input marks for three subjects.
o Calculation: It calculates the total marks by summing the marks of the three
subjects and computes the percentage based on the total marks out of 300.
o Class Determination: It assigns a class to the student based on the calculated
percentage using the specified criteria (Distinction, First Class, Second Class,
or Fail).
o Result Display: It displays the total marks, percentage, and class obtained by
the student.
Quiz:
1. In the algorithm for the mark sheet script, what's the maximum possible score
assumed for the three subjects?
Answer: In the algorithm for the mark sheet script, the maximum possible score
assumed for the three subjects is 300.
3. What are the key components of the mark sheet generation algorithm?
Answer:
The key components of the mark sheet generation algorithm are:
· Initialization
· Input Marks
· Calculate Total and Percentage
· Determine Class
· Display Result
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 6
Aim: Write a shell script to display the multiplication table of a given number.
Date:
Objectives:
1. Understand how to take user input in a shell script.
2. Implement loops for repetitive tasks in scripts.
3. Manipulate and process user input to generate desired outputs.
4. Design and create scripts that serve practical utilities, like a multiplication table
generator.
Theory:
Shell scripting is a powerful tool that allows users to automate tasks in Unix-based
systems. In this context, the script will automate the task of generating a multiplication table
for a specified number. The multiplication table helps in understanding the repeated
addition of the same number.
Procedure:
1. Start the script.
2. Declare variables for the given number and an iterator for looping.
3. User Input:
- Prompt the user to enter a number for which they wish to see the multiplication table.
- Store this number in the respective variable.
240163116010
Observations:
Code:
i=1
until [ $i -gt 10 ]
do
mul=$(( $n * $i ))
i=$(( $i + 1 ))
done
Output:
Result: The script generates a multiplication table for the specified number up to 10
iterations.
Conclusion: This shell script showcases the automation capability of shell scripting in Unix-
based systems for mathematical operations like generating multiplication tables
Quiz:
1. What is the main purpose of the shell script described in the practical?
Answer: The main purpose of the shell script described in the practical is to
automate the generation of a multiplication table for a specified number.
2. How many times does our multiplication table loop to display results?
Answer: The multiplication table loop in the script displays results up to 10
iterations.
3. If a user enters the number "6", what would be the result displayed for the third
iteration of the multiplication table?
Answer: If a user enters the number "6", the result displayed for the third iteration
of the multiplication table would be: 6 x 3 = 18
240163116010
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 7
Date:
Objectives:
1. To introduce students to the mathematical concept of factorials.
2. To demonstrate the use of loops in computing factorials using shell scripting.
3. To enhance the students' ability to design and implement scripts for specific mathematical
tasks.
4. To highlight the versatility of shell scripting in handling a variety of computational
problems.
Theory:
The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers
less than or equal to n. Mathematically, the factorial function n! can be defined by:
1 if n = 0
n * (n-1)! if n > 0
Procedure:
1. Start the script.
2. Declare necessary variables: one for the input number \( n \) and another for storing the
factorial result.
3. User Input:
- Prompt the user to enter a number \( n \) for which they wish to find the factorial.
- Store this number.
4. Factorial Calculation:
- Initialize the factorial result variable as 1.
- Use a loop (e.g., a "while" or "for" loop) that runs from 1 to \( n \).
- In each iteration, multiply the factorial result variable by the current iterator value.
- After the loop completes, the factorial result variable will hold the factorial of \( n \).
240163116010
5. Display Result:
- Print the factorial of \( n \).
Observations:
Code:
factorial()
{
n=$1
fact=1
until [ $n -le 1 ]
do
fact=$(( fact * n ))
n=$(( n - 1 ))
done
factorial $n
Output:
Result: If the user enters b=7, the script will display the Factorial of 7 is 5040.
Conclusion: The script effectively demonstrates generating factorial using loops in the
function in shell scripting, providing a hands-on experience in automating such tasks.
Quiz:
1. What is the factorial of a number?
Answer: The factorial of a non-negative integer ( n ), denoted as ( n! ), is the product
of all positive integers less than or equal to ( n ). For example, the factorial of 4 (( 4! ))
is ( 4 x 3 x 2 x 1 = 24 ).
240163116010
3. If the user inputs the number "5" for n, what value will the script compute?
Answer: If the user inputs the number "5" for ( n ), the script will compute the
factorial as ( 5! = 5 x 4 x 3 x 2 x 1 = 120 ).
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 8
Aim: Write a shell script that accepts a number b and displays the first n prime
numbers as output.
Date:
Objectives:
1. To introduce students to the concept of prime numbers and their properties.
2. To demonstrate the use of loops and conditions in generating specific numeric sequences
in shell scripting.
3. To encourage logical thinking and problem-solving through algorithm design.
4. To provide hands-on experience in writing scripts that take user input and generate
specific outputs.
Theory:
A prime number is a natural number greater than 1 that is not a product of two smaller
natural numbers. In other words, it has only two distinct positive divisors: 1 and itself. For
instance, the first six prime numbers are 2, 3, 5, 7, 11, and 13. Shell scripts allow automation
of such tasks where repetitive checking or calculations, like checking for prime numbers, are
needed.
Procedure:
2. Declare necessary variables: one for the input number b, a counter for found prime
numbers, and an iterator for checking each number.
3. User Input:
- Prompt the user to enter a number b indicating how many prime numbers they wish to
see.
- Store this number.
Observations:
Code:
if [ $flag -eq 1 ]
then
echo " $i is prime "
x=$(( $x + 1 ))
fi
i=$(( $i + 1 ))
done
}
prime $n
Output:
Result: If the user enters b=4, the script will display the first 4 prime numbers: 2, 3, 5, and 7.
Sufficient space to be provided
240163116010
Conclusion: The script effectively demonstrates generating prime numbers using loops and
conditional statements in shell scripting, providing a hands-on experience in automating
such tasks.
Quiz:
1. What is a prime number?
Answer: A prime number is a natural number greater than 1 that is not a product of
two smaller natural numbers.
3. If the user enters the number "4" for b, how many prime numbers will the script
display?
Answer: If the user enters the number "4" for ( b ), the script will display the first 4
prime numbers. These prime numbers are: 2, 3, 5, and 7.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 9
Aim: Write a shell script which will generate first n Fibonacci numbers like: 1,
1, 2, 3, 5, 13,18
Date:
Objectives:
1. To teach students about the Fibonacci sequence and its properties.
2. To demonstrate the use of loops and arithmetic operations in generating
the Fibonacci sequence using shell scripting.
3. To instill logical and sequential thinking in algorithm design.
4. To offer a practical exercise in writing scripts for generating numeric
patterns.
Theory:
The Fibonacci sequence is a series of numbers in which each number is the sum of
the two preceding ones. Typically, the sequence starts with 0 and 1. In mathematical terms,
the sequence F(n) is defined by the recurrence relation:
Procedure:
2. Declare necessary variables: one for the input number n, and two initial seed numbers for
the Fibonacci sequence (0 and 1).
3. User Input:
- Prompt the user to enter a number n indicating how many Fibonacci numbers they wish
to see.
- Store this number.
Observations:
Code:
a=0
b=1
done
Output:
Result: If the user enters n=6, the script will display the first 6 Fibonacci numbers: 0, 1, 1, 2,
3, and 5.
Conclusion: The script effectively demonstrates generating Fibonacci numbers using loops
and arithmetic operations in shell scripting, providing a practical exercise in generating
numeric sequences.
Quiz:
1. How is each number in the Fibonacci sequence generated?
Answer: Each number in the Fibonacci sequence (starting from the third number) is
generated by adding the two preceding numbers. Mathematically, it follows the
recurrence relation ( F(n) = F(n-1) + F(n-2) ) where ( F(0) = 0 ) and ( F(1) = 1 ).
240163116010
3. If the user inputs the number "6" for n, how many Fibonacci numbers will the
script display?
Answer: If the user inputs the number "6" for ( n ), the script will display the first 6
Fibonacci numbers.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 10
Aim: Write a menu-driven shell script that presents the following options to the
user and executes the corresponding task:
Date:
Objectives:
1. To teach students how to create interactive, menu-driven shell scripts.
2. To familiarize students with various built-in UNIX commands and their utilities.
3. To instill a practical understanding of how to use shell scripting to automate and
streamline tasks.
4. To demonstrate the concept of loops and conditional statements in creating interactive
scripts.
Theory:
A menu-driven program provides users with a selection of choices in the form of a menu.
The user's choice determines the action the program will take. In a shell script, such menu-
driven interfaces can be built using loops, conditional statements, and built-in commands.
Procedure:
1. Start the script.
2. Display Menu:
- Use a loop (e.g., a "while" loop) to repeatedly display the menu and prompt for user input
until the user chooses to exit.
- Display the options:
a. Display calendar of the current month
b. Display today’s date and time
c. Display usernames currently logged in the system
d. Display your name at a given x, y position
e. Display your terminal number
f. Exit
240163116010
3. Get User Input:
- Prompt the user to select an option from the menu.
Observations:
Code:
echo " A. Calendar of Current Month "
echo " B. Today's Date & Time "
echo " C. Current logged-in User "
echo " D. Name at any Position "
echo " E. Terminal Number "
echo " F. Exit "
mul=0
case $op in
"A" | "a" )
echo " Calender of Current Month is : "
cal
;;
"B" | "b")
echo " Today's Date & Time is : "
date
;;
"C" | "c")
echo "Current logged-in user is : "
who
;;
"D" | "d")
row=$(tput lines)
col=$(tput cols)
echo "Terminal Window has Rows=$row Cols=$col"
echo "Enter X & Y Position "
read x
read y
tput cup $x $y
echo "$name"
;;
"E" | "e")
echo "Terminal Number is : "
tty
;;
"F" | "f" )
echo "Exiting ... "
mul=1
exit
;;
*)
esac
done
Output:
Result: When the user runs this script, they will be presented with a menu and can choose
options to perform various tasks.
240163116010
Conclusion: The script effectively demonstrates creating a menu-driven interface in a shell
script, allowing users to interactively choose and execute tasks.
Quiz:
1. Which command is used to display the calendar of the current month?
Answer: The `cal` command is used to display the calendar of the current month in
the shell script.
2. How can you display the names of users currently logged in to the system?
Answer: The `who` command is used to display the names of users currently logged
in to the system in the shell script.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 11
Aim: Write a shell script to read n numbers as command arguments and sort
them in descending order
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.
Objectives:
1. To familiarize students with the use of command-line arguments in shell scripts.
2. To introduce the concept of sorting and its implementation using loops.
3. To encourage the use of arrays in shell scripting for data processing.
4. To demonstrate the practical utility of shell scripts in processing and displaying sorted
data.
Theory: Command-line arguments are a method of passing input to a script at the time of
execution. In shell scripting, these arguments can be accessed via special variables: $1, $2,
$3, ... representing the first, second, third argument, and so on. $# holds the count of total
arguments passed. Sorting is the process of arranging items systematically. For this task, we
will arrange numbers in descending order.
Procedure:
5. Display Result:
- Print the sorted numbers.
240163116010
6. End the script.
Observations:
Code:
#!/bin/bash
i=0
declare -a arr
until [ $i -ge $n ]
do
echo "Enter value of arr[$i]: "
read arr[$i]
i=$(( $i + 1 ))
done
k=0
until [ $k -ge $n ]
do
j=0
while [ $j -le $(( $n - $k - 1 )) ]
do
if [[ ${arr[$j]} -lt ${arr[$(( $j + 1 ))]} ]]
then
temp=${arr[ $j ]}
arr[$j]=${arr[$(( $j + 1 ))]}
arr[$(( $j + 1 ))]=$temp
fi
j=$(( $j + 1 ))
done
k=$(( $k + 1 ))
done
echo "Numbers in Descending order: "
echo "${arr[*]} "
Output:
240163116010
Result: When the script is executed with command-line arguments (e.g.,
./sort_descending.sh 5 2 7 1), it will sort the numbers in descending order and display the
sorted numbers.
Conclusion: The script effectively sorts numbers in descending order using the bubble sort
algorithm and demonstrates the use of command-line arguments and arrays in shell
scripting.
Quiz:
1. How can you access the first command-line argument in a shell script?
Answer: You can access the first command-line argument in a shell script using the
special variable `$1`.
2. What special variable holds the total count of command-line arguments passed to a
script?
Answer: The special variable `$#` holds the total count of command-line arguments
passed to a script.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 12
Aim: Write a shell script to display all executable files, directories, and zero-
sized files from the current directory.
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.
Objectives:
1. To educate students about the permission system of UNIX-like operating systems and its
significance.
2. To demonstrate the ability to filter and display directory content based on specific criteria
using shell scripting.
3. To encourage students to explore various commands and options that can be used to
glean information about files.
4. To provide a hands-on experience in creating scripts that present organized information
based on file attributes.
Theory:
In UNIX-like operating systems, files and directories have associated *permissions* that
determine who can read, write, or execute them. An executable file is one that has the
execute permission set for the user, group, or others. Directories with the execute
permission can be accessed and traversed. A zero-sized file, as the name suggests, has a size
of 0 bytes.
Using the ls command with specific options and filters, one can list files based on their
attributes. Combined with if conditions, shell scripts can be used to detect and display files
with specific properties.
Procedure:
1. Start the script.
Code:
Output:
Result: When executed, the script will display all executable files, directories, and zero-sized
files from the current directory.
Conclusion: The script effectively demonstrates how to filter and display files based on
their attributes using shell scripting and the ls command with specific options and
conditions.
Quiz:
1. How can you identify an executable file in a UNIX-like system?
Answer: In a UNIX-like system, you can identify an executable file by checking its
execute permission. If the execute permission is set for the user, group, or others, the
file is considered executable. This can be checked using the ls -l command, where an
"x" in the permission field indicates execute permission.
240163116010
2. What is the significance of the execute permission on a directory?
Answer: The execute permission on a directory is significant because it allows users
to access and traverse the directory. Without the execute permission, users won't be
able to list the contents of the directory or access files within it, even if they have
read permission on those files. Essentially, the execute permission on a directory
controls whether users can enter and interact with it.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 13
Aim: Write a shell script to check if the entered string is a palindrome or not.
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.
Objectives:
1. To introduce students to the concept of palindromes and how to programmatically
identify them.
2. To teach students about string operations and comparisons in shell scripting.
3. To promote logical thinking and the utilization of string manipulation techniques.
4. To give students a hands-on experience in creating scripts that evaluate and provide
feedback on string-based user input.
Theory:
A palindrome is a word, phrase, number, or other sequences of characters that reads the
same forward and backward (ignoring spaces, punctuation, and capitalization). Examples of
palindromic words are "radar", "level", and "deified". In this practical, the focus will be on
checking palindromic words. To determine if a string is a palindrome, we compare the string
to its reverse. If they are the same, the string is palindromic.
Procedure:
1. Start the script.
2. User Input:
- Prompt the user to enter a string.
- Store this string.
3. Check if Palindrome:
- Reverse the entered string.
- Compare the reversed string with the original string.
- If they match, the string is a palindrome.
- If not, the string is not a palindrome.
4. Display Result:
- Print the result based on the comparison.
240163116010
Observations:
Code:
i=$length
while [ $i -ge 0 ]
do
rev_str="$rev_str$( expr substr $str $i 1 )"
i=$(( $i - 1 ))
done
if [ $str = $rev_str ]
then
echo " Reverse string & Original string are same , So $str is Pailindrome "
else
echo " Reverse string & Original string aren't same , So $str isn't Paillindrome "
fi
Output:
Result: When we executing, the script will prompt to enter a string. After entering the
string, it will determine if the string is a palindrome or not and display the result.
Quiz:
1. What is a palindrome?
Answer: A palindrome is a word, phrase, number, or sequence of characters that
reads the same backward as forward. For example, "radar," "level," and "deified" are
palindromic words.
240163116010
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 14
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.
Objectives:
1. To familiarize students with the concept of filters in UNIX and their applications.
2. To introduce students to the capabilities and uses of grep, egrep, and fgrep.
3. To encourage the use of filtering commands in processing and searching text data.
4. To provide insights into how pattern searching and regular expressions work in UNIX-like
systems.
Theory:
Filters in UNIX are commands that process text data, producing useful transformations on
the input. They are often combined with other commands using pipes | to process streams of
data.
Among the many filters, grep and its variants (egrep and fgrep) are especially popular:
- grep: Stands for "global regular expression print." It searches the given file for lines
containing a match to the given pattern or string. By default, grep displays the matching
lines.
- egrep: Stands for "extended grep". It functions the same as grep -E and treats patterns as
extended regular expressions.
- fgrep: Stands for "fixed grep". It functions the same as grep -F and treats patterns as fixed
strings (no special characters, etc.)
Procedure:
1. Using grep:
- Command: grep 'pattern' filename
- Use case: To search for a specific pattern in a file.
2. Using egrep:
- Command: egrep 'pattern1|pattern2' filename
- Use case: To search for lines containing either "pattern1" or "pattern2" in a file using
extended regular expressions.
240163116010
3. Using fgrep:
- Command: fgrep 'pattern' filename
- Use case: To search for a string without treating any characters as special characters or
regular expressions.
Observations:
Code:
Output:
Result: The provided shell script demonstrates the usage of grep, egrep, and fgrep
commands in UNIX/Linux shell programming. When executed, the script creates a sample
text file and performs pattern matching operations using these filtering commands.
Conclusion: The experiment successfully showcased the capabilities of grep, egrep, and
fgrep commands in filtering text data based on specified patterns or strings. Students gained
practical experience in using these commands to search for and display lines matching
specific criteria within a file. Understanding and utilizing such filters are essential skills for
text processing and pattern matching tasks in UNIX/Linux environments.
Quiz:
1. What does the grep command do in UNIX?
Answer: The grep command in UNIX searches for lines in files that match a specified
pattern or string and then print those lines.
240163116010
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 15
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system.
Theory:
1. Unix Shell:
- The Unix shell is both a command-line interface and a powerful scripting environment. It
provides an interface for users to interact with the Unix operating system.
- Various shells are available, such as the Bourne Shell (sh), Bourne Again Shell (bash), C
Shell (csh), and the Korn Shell (ksh), each with its own set of features and syntax.
- The shell reads commands typed by a user and translates them into a form that the
operating system can understand. It also provides functionalities such as variable
substitution, loops, and conditionals within shell scripts.
2. Environment Variables:
- Environment variables are a set of dynamic named values that can affect the way running
processes behave on a computer. They exist as part of the environment in which a process
runs.
- These variables are used by the shell and other programs to get information about the
environment, like the home directory, current path, or the terminal type.
- Some common environment variables include PATH (which specifies directories where
executable programs are located), HOME (which indicates the home directory of the current
user), and LANG (which defines the system's language and character set).
Procedure:
1. Accessing Environment Variables:
- You can access an environment variable in the shell using the syntax $VARIABLE_NAME.
For instance, echo $HOME will display the home directory of the current user.
Environment variables or ENVs basically define the behavior of the environment. They can
affect the processes ongoing or the programs that are executed in the environment. Scope of
an environment variable:- Scope of any variable is the region from which it can be accessed
or over which it is defined. An environment variable in Linux can have global or local scope.
Global: - A globally scoped ENV that is defined in a terminal can be accessed from anywhere
in that particular environment which exists in the terminal. That means it can be used in all
kind of scripts, programs or processes running in the environment bound by that terminal.
Local A locally scoped ENV that is defined in a terminal cannot be accessed by any program
or process running in the terminal. It can only be accessed by the terminal (in which it was
defined) itself.
Result: Familiarity with different shells and their functions, ability to manage environment
variables, and practical knowledge of commands like `echo`, `export`, and `printenv`.
Quiz:
1. What is the role of the UNIX shell?
Answer: The role of the UNIX shell is to provide a command-line interface and scripting
environment, allowing users to interact with the operating system by executing commands
and writing scripts.
3. How can you display the value of an environment variable named VAR_NAME?
Answer: You can display the value of an environment variable named VAR_NAME using the
`echo` command with the syntax `$VAR_NAME`. For example, to display the value of a
variable named MYVAR, you would use `echo $MYVAR`.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 16
Aim: Write a shell script to validate the entered date. (eg. Date format is: dd-
mm-yyyy).
Date:
Objectives:
1. To introduce students to the concept of date validation and the intricacies associated with
calendar systems.
2. To teach students about the conditions that determine leap years and how they affect date
validation.
3. To encourage logical thinking and problem-solving through the implementation of
validation checks.
4. To provide hands-on experience in validating and processing user input in shell scripts.
Theory:
Date validation is the process of ensuring that a given date string matches a specified
format and represents a valid calendar date. In this context, the date format is "dd-mm-
yyyy". Validation needs to consider factors like the number of days in each month and leap
years.
Procedure:
1. Start the script.
2. User Input:
- Prompt the user to enter a date in the format "dd-mm-yyyy".
- Store this date.
4. Validation:
- Check if the extracted day, month, and year are numeric values.
- Ensure the month is between 01 and 12.
- Ensure the day is between 01 and the maximum valid day for the given month (e.g., 01-31
for January, 01-28 or 01-29 for February depending on whether the year is a leap year or
not).
- A year is a leap year if:
- It is divisible by 4 and not divisible by 100 OR
- It is divisible by 400.
240163116010
5. Display Result:
- If the date is valid, print a message confirming its validity.
- Otherwise, print an error message.
Observations:
Code:
length=${#date}
if [ $length -eq 10 ]
then
case $month in
01 |03 |05 |07 |08 |10 |12 )
days=31
;;
04 |06 |09 |11 )
days=30
;;
02 )
if [ $(( $year % 4 )) -eq 0 ]
then
days=29
else
days=28
fi
;;
* )
days=0
;;
esac
fi
if [ $day -ge 0 ] && [ $day -le $days ]
then
echo " $date is valid date "
else
echo " Invalid Date "
fi
else
echo "Invalid Date "
fi
240163116010
else
echo " Invalid Format of Date "
fi
Output:
Result: If the user enters a date in the correct "dd-mm-yyyy" format and it is a valid
calendar date, the script will display a message confirming its validity.If the input date
format is incorrect or the date is invalid (e.g., February 30), the script will display an error
message indicating the issue.
Conclusion: This shell script effectively validates user input for dates in the "dd-mm-yyyy"
format. It breaks down the date into day, month, and year components and performs checks
to ensure the date is within valid ranges and adheres to the rules of leap years. By
incorporating string manipulation and conditional statements, the script provides a robust
method for date validation in Unix-like systems.
Quiz:
1. What is the primary reason February can have either 28 or 29 days?
Answer: February can have either 28 or 29 days due to the leap year rule, which
adds an extra day to February every four years to keep the calendar year
synchronized with the astronomical year.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 17
Aim: Write an awk program using function, which convert each word in a given
text into capital.
Date:
Objectives:
1. To introduce students to the capabilities and functionalities of the awk programming
language, especially in the realm of text processing.
2. To showcase the design and application of custom functions in awk.
3. To instill an understanding of pattern matching, data processing, and transformation
using awk.
4. To provide a clear and structured approach to capitalizing text, emphasizing algorithmic
thinking and design.
Theory:
awk is a text-processing programming language that is particularly well-suited for
structured data and produces formatted reports. The language is data-driven and is used for
pattern scanning and processing. It provides a way to create small and simple programs to
transform and report on data within files.
A crucial aspect of awk is its ability to match patterns and perform actions on the
matched data. Functions, both built-in and user-defined, can further extend its capabilities.
One such task is to capitalize the first letter of each word in a text.
Procedure:
1. Define the Capitalize Function:
- Accept a string as input.
- Extract the first letter of the string and convert it to uppercase.
- Append the remainder of the string (from the second character onwards) to the
uppercase letter without changing its case.
- Return the combined result as the capitalized word.
Observations:
Code:
UpperCase()
{
UpperCase $str
Output:
Result: The result of the experiment aligns with the theoretical expectations. The awk
program successfully capitalized each word in the input text, demonstrating the
effectiveness of using awk for text processing tasks. This experiment showcased the
capabilities of awk in manipulating and transforming textual data, highlighting its role in
automating text-related operations.
Conclusion: This awk program successfully capitalizes each word in the input text using a
custom capitalize function. It demonstrates the power and flexibility of awk in text
processing tasks, allowing for efficient manipulation and transformation of textual data.
Quiz:
1. What is awk primarily used for?
Answer: Awk is primarily used for text processing and manipulation, particularly in
structured data and reporting tasks.
3. In the context of the provided algorithm, what is the main purpose of the capitalize
function?
Answer: The main purpose of the capitalize function in the provided algorithm is to
convert the first letter of each word in a text to uppercase while preserving the rest
of the word in its original case.
240163116010
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 18
Aim: Write a program for process creation using C. (Use of gcc compiler)
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system
Objectives:
1. To introduce students to the fundamentals of process management in UNIX-like operating
systems.
2. To educate on the usage and significance of the fork() system call in creating new
processes.
3. To demonstrate the creation and differentiation of parent and child processes in a C
program.
4. To foster an understanding of how processes are managed and controlled in a UNIX
environment.
Theory:
In UNIX-like operating systems, the creation of a new process is accomplished using
the fork() system call. When a process calls fork(), it creates a new process called the child
process. The original process is called the parent process.
The child process is an almost exact copy of the parent process. Both processes will
continue executing from the point of the fork() call. The main difference is the value
returned by fork(). In the child process, fork() returns 0, while in the parent, it returns the
child's process ID.
This distinction can be utilized to differentiate the roles of the parent and child processes in
the program.
Procedure:
1. Begin the program.
2. Call the fork() function.
3. Check the return value of fork().
- If the return value is negative, the fork failed.
- If the return value is zero, the current code block is being executed by the child process.
- If the return value is positive, the current code block is being executed by the parent
process.
4. In the child process, print a message indicating that it's the child process and display its
process ID.
240163116010
5. In the parent process, print a message indicating that it's the parent process, display its
process ID, and also display the child's process ID.
6. End the program.
Observations:
Code:
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if (pid < 0)
{
fprintf(stderr, "Fork failed\n");
return 1;
}
else if (pid == 0)
{
printf("Child process: PID = %d\n", getpid());
}
else
{
printf("Parent process: PID = %d\n", getpid());
printf("Child process ID: %d\n", pid);
}
return 0;
}
Output:
Result: The result of running the provided C program to demonstrate process creation
using fork() would be the output indicating whether the current process is the parent or
child, along with their respective process IDs.
240163116010
Quiz:
1. What is the primary function used to create a new process in UNIX-like systems?
Answer: The primary function used to create a new process in UNIX-like systems is
the `fork()` system call.
2. How can you differentiate between the child and parent processes after the fork()
call?
Answer: You can differentiate between the child and parent processes after the
`fork()` call by checking the return value of `fork()`. In the child process, `fork()`
returns 0, while in the parent process, it returns the process ID (PID) of the child
process.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 19
Date:
Relevant CO: Evaluate the requirement for process synchronization and coordination
handled by operating system
Objectives:
1. To introduce students to the foundational concepts of virtual machines and the broader
realm of virtualization.
2. To impart knowledge about the advantages, challenges, and use cases of virtualization in
modern IT infrastructures.
3. To educate on the roles and functions of hypervisors in a virtualized environment.
4. To provide insights into various types of virtualization, enabling students to make
informed decisions in real-world applications.
Theory:
1. Virtual Machines (VM):
- A Virtual Machine (VM) is a software-based simulation of a physical computer. It runs in
an isolated environment on a host system with the help of virtualization software. A VM
operates similarly to a physical computer, having its own CPU, memory, disk space, and I/O.
2. Virtualization:
- Virtualization refers to the act of creating a virtual (rather than physical) version of
computing resources. It allows for the creation of multiple virtual environments on a single
physical system.
- At the heart of virtualization is the *hypervisor*, a software layer or platform that
manages the distribution of the underlying hardware resources to the virtual machines.
There are two types of hypervisors:
a. Type 1 (Bare Metal): Runs directly on the system's hardware.
b. Type 2 (Hosted): Runs atop a conventional operating system.
Advantages of Virtualization:
1. Resource Efficiency: Multiple VMs can run on a single physical server, optimizing
hardware usage.
2. Isolation: VMs are isolated from each other. If one VM crashes, it doesn’t affect others.
3. Snapshot and Cloning: VMs can be snapshotted to capture their current state, allowing
easy rollback. They can also be cloned for quick deployment.
240163116010
4. Flexibility and Testing: VMs can run different operating systems on the same physical
host, which is beneficial for application testing across different environments.
5. Cost Savings: Virtualization can reduce the need for physical hardware, leading to cost
savings in hardware procurement and energy consumption.
Types of Virtualization:
1. Hardware/Platform Virtualization: Creation of VMs which act like real computers with
an operating system.
2. Network Virtualization: Splitting available bandwidth in a network into independent
channels which can be assigned to particular servers or devices.
3. Storage Virtualization: Pooling physical storage from multiple devices and presenting it
as a single storage device.
4. Application Virtualization: Packaging an application along with its runtime
environment to run on any compatible underlying OS.
Observations:
Virtualization has become a crucial aspect of modern IT infrastructures due to its numerous
benefits. It allows organizations to maximize resource utilization, improve flexibility and
scalability, enhance disaster recovery capabilities, and reduce overall costs. The ability to
create and manage virtual machines efficiently enables IT departments to streamline
operations, increase agility, and adapt to changing business needs more effectively.
Additionally, virtualization facilitates better utilization of hardware resources, leading to
improved energy efficiency and reduced environmental impact. Overall, virtualization plays
a vital role in optimizing IT environments and supporting business growth and innovation.
Quiz:
1. What is the primary software component responsible for managing virtual
machines and their access to the physical hardware?
Answer: The primary software component responsible for managing virtual
machines and their access to the physical hardware is the hypervisor.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010
Experiment No: 20
Date:
Relevant CO: Describe and analyze the memory management and its allocation
policies.
Objectives:
1. To familiarize students with the realm of virtualization and the role of hypervisors in
creating and managing virtual environments.
2. To introduce the features and functionalities of VMWare ESXi, Microsoft Hyper-V, and Xen
Server, enabling informed decision-making in IT infrastructures.
3. To impart the knowledge of the Java Virtual Machine's workings and its importance in the
Java ecosystem.
4. To encourage the exploration and comparison of various virtualization technologies,
understanding their strengths, weaknesses, and use cases.
Theory:
1. Hypervisors:
- A hypervisor, often termed a Virtual Machine Monitor (VMM), is software, firmware, or
hardware that creates and runs virtual machines. It divides the host system's resources to
allocate them to the VMs.
2. VMWare ESXi:
- VMWare ESXi is a Type 1 hypervisor integrated into VMware's vSphere suite. It's a bare-
metal hypervisor that installs directly onto the physical server and doesn't require an
underlying operating system.
- It offers centralized management, automation, and scalability capabilities.
3. Microsoft Hyper-V:
- Microsoft Hyper-V is a hypervisor-based virtualization system, part of Windows Server
editions. It's available both as a standalone product and an integrated feature of the
Windows OS.
- Hyper-V can create both VMs and containers, offering robustness and flexibility for
different virtualization needs.
240163116010
4. Xen Server:
- Xen is an open-source Type-1 or bare-metal hypervisor, initially developed by the
University of Cambridge and now hosted by the Linux Foundation.
- Xen is used by many cloud providers and offers features like live migration, VM cloning,
and a high level of security.
5. Java VM (JVM):
- The JVM is a virtualization engine for running Java bytecode. It isn't a hypervisor in the
same sense as the others listed but acts as a virtual machine that provides a runtime
environment to execute Java applications.
- Java applications are compiled into bytecode, which is executed by the JVM. This allows
Java applications to be platform-independent, adhering to the "write once, run anywhere"
(WORA) principle.
Conclusion: Hypervisors like VMWare ESXi, Microsoft Hyper-V, and Xen Server are crucial
for optimizing resource usage and enhancing IT infrastructure flexibility. Each has unique
features catering to various virtualization needs.The Java Virtual Machine (JVM) plays a
pivotal role in Java's platform independence, executing bytecode across different platforms
seamlessly.Understanding these technologies is essential for efficient resource management
and application deployment in modern IT environments.
Quiz:
1. Which of the mentioned hypervisors is integrated into VMware's vSphere suite?
Answer: VMWare ESXi is integrated into VMware's vSphere suite.
2. What distinguishes the Java Virtual Machine from hypervisors like ESXi and Hyper-
V?
Answer: The Java Virtual Machine (JVM) is distinct from hypervisors like ESXi and
Hyper-V as it executes Java bytecode rather than creating and managing virtual
machines.
3. Why is the JVM crucial for Java's "write once, run anywhere" principle?
Answer: The JVM is crucial for Java's "write once, run anywhere" principle because
it abstracts the underlying hardware and operating system details, allowing Java
applications to be platform-independent.
Suggested Reference:
Rubrics 1 2 3 4 5 Total
Marks
240163116010