0% found this document useful (0 votes)
38 views23 pages

Os Practical

This document certifies that Mr. Chowdhary Shanmukha Naidu has successfully completed laboratory experiments in the Operating System Laboratory during the academic year 2024/25 at Parul University. It includes an index of practical exercises covering Linux commands, shell programming, and C programming tasks. The document also provides detailed algorithms and shell scripts for various programming assignments.

Uploaded by

benditarun20045
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)
38 views23 pages

Os Practical

This document certifies that Mr. Chowdhary Shanmukha Naidu has successfully completed laboratory experiments in the Operating System Laboratory during the academic year 2024/25 at Parul University. It includes an index of practical exercises covering Linux commands, shell programming, and C programming tasks. The document also provides detailed algorithms and shell scripts for various programming assignments.

Uploaded by

benditarun20045
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/ 23

FACULTY OF ENGINEERING AND TECHNOLOGY

BACHELOR OF TECHNOLOGY

Operating System Laboratory


(303105252)

4th Semester
Computer Science & Engineering Department
PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
CERTIFICATE

This is to certify that Mr. Chowdhary Shanmukha Naidu with


Enrollment No. 2303031241592 has Successfully completed
laboratory experiments in Operating System
Laboratory during academic year 2024/25

Date:

Signature Signature
(Head of department) (Lab teacher)

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

INDEX
SR. Page Perform Assess Marks Sign
N
Title No. ance -ment
O
Date Date
01 Study of Basic
Commands of Linux
02 Study the basics of
Shell programming
03 Write a Shell script
to print given
numbers sum of all
digits
04 Write a shell script
to validate the
entered date.
05 Write a shell script
to check entered
string is palindrome
or not.
06 Write a Shell script
to say good
morning/Afternoon
/Evening as you log
in to system
07 Write a C program
to create a child
process.
08 Finding out from
given biggest three

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
numbers supplied as
command line
arguments.
09 Printing the for loop
patterns using loops
10 Shell script to
determine whether
given file exist or
not.
11 Write a program for
process creation
using C.
12 Implementation of
FCFS &Round
Robin Algorithm.
13 Implementation of
Banker’s Algorithm.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

Practical – 01
Aim: Study of Basic Commands of Linux.

1. pwd Command: The pwd command is used to display the location of the
current working directory.
2. touch Command: The touch command is used to create empty files. We
can create multiple empty files by executing it once.
3. cd Command: The cd command is used to change the current directory.
4. mkdir Command: The mkdir command is used to create a new directory
under any directory.
5. rmdir Command: The rmdir command is used to delete a directory.

6. cat Command: The cat command is a multi-purpose utility in the Linux


system. It can be used to create a file, display content of the file, copy the content
of one file to another file, and more.

7. wc Command: The wc (word count) command, can return the number of


lines, words, and characters in a file.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
8. free Command: The free command Display RAM details in Linux machine.
9. ls Command : The ls command is used to display a list of content of a
directory.
10. whoami Command: Display the username of the current user.

11. mv Command: Moves or renames a file or directory.

12. cp Command: Copies a file or directory.

13. echo Command: Prints the specified text to the terminal.

14. date Command: Displays the current date and time.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

15. clear Command: Clears the terminal screen.

16. git --version Command: Displays the installed Git version.


17. git init: Initializes a new Git repository in the current directory.
18. ls –a: Lists all files, including hidden ones, in the current directory.
19. df : Displays information about disk space usage for file systems.
20. exit: Closes the current terminal session.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 02
Aim: Study the basics of Shell programming
What is Shell?
A shell is a special user program that provides an interface for the
user to use operating system services. Shell accepts human-readable
commands from users and converts them into something which the
kernel can understand. It is a command language interpreter that
executes commands read from input devices such as keyboards or
from files. The shell gets started when the user logs in or starts the
terminal. Shell can be classified into two categories – Command
Line Shell:
Shell can be accessed by users using a command line interface. A
special program called Terminal in Linux/macOS, or Command
Prompt in Windows OS is provided to type in the human-readable
commands such as “cat”, “ls” etc. and then it is being executed. The
result is then displayed on the terminal to the user.
Examples: Bash, Zsh, Korn Shell, C Shell.
Graphical Shell:
Graphical shells provide means for manipulating programs based on
the graphical user interface (GUI), by allowing for operations such as
opening, closing, moving, and resizing windows, as well as switching
focus between windows. Best example of it is Windows OS.
Examples: GNOME Shell, KDE Plasma.
Types of Shell: - (commonly used shells)
1. Bourne Again Shell (Bash)
• Bash is an enhanced version of the original Bourne Shell (sh) and
isthe default shell in most Linux distributions.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
• It supports advanced features like command history, tab
completion, and scripting enhancements.
• Widely used for both interactive use and scripting due to its
portability and robust functionality.
• Bash scripts are highly compatible across Unix-like systems.
• It is user-friendly, making it popular among beginners and
advanced usersalike.
2. C Shell (csh)

• C Shell uses a syntax inspired by the C programming language,


making it familiar to programmers.
• It introduced features like command history, aliases, and job
control in Unix environments.
• Best suited for interactive use rather than scripting due to less
consistent syntax.
• Less commonly used today, as alternatives like Bash and Zsh
offer more features.

Steps to creating a shell script:


1. Open a text editor like notepad and write a script. Save the script with
the .sh extension.
Here we saved a script with the name samplescript.sh

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

2. Open terminal navigates to scripts’s directory. In our example file is


already on desktop.
3. Make script executable. For achieve this use the command chmod +x
samplescript.sh
Run the script. In example we run the script with ./samplescript.sh
here ./ is important because it tells the shell to execute the script in
current directory.
4. Run the script. In example we run the script with ./samplescript.sh here ./ is
important because it tells the shell to execute the script in current directory.

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 03
Aim : Write a Shell script to print given numbers sum of all
digits.
Algorithm:
1. Get a number.
2. Split each digit from the number using the modulo operator.
3. Calculate the sum.
4. Print the result.

Flow-Chart:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
ShellScript:
#!/bin/bash
echo "Enter a number:"
read num
sum=0
while [ $num -gt 0 ]
do
mod=$(expr $num % 10)
sum=$(expr $sum + $mod)
num=$(expr $num / 10)
done
echo "Sum of all digits is: $sum"
echo "Udit"

Output:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 04
Aim: Write a shell script to validate the entered date.
Algorithm:
1. Start
2. Input a date.
3. Check year is leap or not.
4. Check month is (m=1,3,5,7,8,10,12) then date is valid from 1 to 31.
5. Check month is (m=4,6,9,11) then date is valid from 1 to 30.
6. Check month is (m=2) and year is leap year then date is valid from 1to29.
7. Check month is (m=2) and not leap year then date is valid from 1 to 28.
8. Else date is invalid.
9. End.
Flow-Chart:

ShellScript:
dd=0
mm=0

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
yy=0
days=0
echo -n "Enter Day (DD) : "
read dd
echo -n "Enter Month (MM) : "
read mm
echo -n "Enter Year (YYYY) : "
read yy
if [ $mm -le 0 -o $mm -gt 12 ];
then
echo "$mm is invalid month."
exit 1
fi
case $mm in
1) days=31;;
2) days=28;;
3) days=31;;
4) days=30;;
5) days=31;;
6) days=30;;
7) days=31;;
8) days=31;;
9) days=30;;
10) days=31;;
11) days=30;;
12) days=31;;

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
*) days=-1;;
esac
if [ $mm -eq 2 ];
then
if [ $((yy % 4)) -ne 0 ] ; then
:
elif [ $((yy % 400)) -eq 0 ] ; then
days=29
elif [ $((yy % 100)) -eq 0 ] ; then
:
else
days=29
fi
fi
if [ $dd -le 0 -o $dd -gt $days ];
then
echo "$dd Is An Invalid Date."
exit 3
fi
echo "$dd/$mm/$yy Is A Valid Date."
Output:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 05
Aim: Write a shell script to check entered string is
palindrome or not.
Algorithm:
1. Start.
2. Get the string from user.
3. Hold the string in temporary variable.
4. Reverse the string.
5. Compare the temporary string with reversed string.
6. Both string are same, then print ”The String is palindrom”.
7. Else print “The String is not a palindrom”.
8. End.
Flow-Chart:

ShellScript:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
#!/bin/bash

is_palindrome() {
local str="$1"
local reversed_str=""
local length=${#str}

for (( i=$length-1; i>=0; i-- )); do


reversed_str+="${str:$i:1}"
done

if [ "$str" == "$reversed_str" ]; then


echo "The string '$str' is a palindrome."
else
echo "The string '$str' is not a palindrome."
fi
}

read -p "Enter a string: " input_string


is_palindrome "$input_string"
Output:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

Practical – 06
Aim: Write a Shell script to say Good Morning / Afternoon /
Evening / Night as you log in to System.
ShellScript:
#!/bin/bash
hour=$(date +%H)
if [ $hour -ge 5 ] && [ $hour -lt 12 ]; then
greeting="Good Morning"
elif [ $hour -ge 12 ] && [ $hour -lt 17 ]; then
greeting="Good Afternoon"
elif [ $hour -ge 17 ] && [ $hour -lt 21 ]; then
greeting="Good Evening"
else
greeting="Good Night"
fi
echo "$greeting, $(whoami)!"
Output:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 07
Aim: Write a C program to create a child process.
Code:
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid = fork();
if (pid < 0){
perror("Fork failed");
return 1;
}
if (pid == 0){
printf("\nChild PID: %d\n", getpid());
printf("Parent PID: %d\n", getppid());
}
else{
printf("\nParent PID: %d\n", getpid());
printf("Child PID: %d\n", pid);
}
return 0;
}

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR

Output:

Enrollment No: 23030312401592


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 08
Aim: Find out the biggest number from the given three numbers
supplied as command line arguments.
ShellScript:
echo "Enter Three Numbers:"
read num1 num2 num3

if [[ $num1 -ge $num2 && $num1 -ge $num3 ]];


then
echo "The Largest Number: $num1"
elif [[ $num2 -ge $num1 && $num2 -ge $num3 ]];
then
echo "The Largest Number: $num2"
else
echo "The Largest Number: $num3"
fi

Output:

Enrollment No: 2303031241592 Name: R.Dharanidhar reddy


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 09
Aim: Printing patterns using loop.
ShellScript:
read -p "Enter The Value For Pattern: " p
for (( m=1; m<=p; m++ ))
do
for (( a=m; a<=p; a++ ))
do
echo -ne " "
done
for (( n=1; n<=m; n++ ))
do
echo -ne "*"
done
for (( i=1; i<m; i++ ))
do
echo -ne "*"
done
echo
done
Output:

Enrollment No: 2303031241592 Name: R.Dharanidhar reddy


PARUL UNIVERSITY
FACULTY OF ENGINEERING AND TECHNOLOGY
OPERATING SYSTEM (303105252) B. TECH.
2NDYEAR
Practical – 10
Aim: Shell Script to determine whether a given file exists or not.
ShellScript:
echo "Enter Your Filename:"
read newfile1

if [ -f "$newfile1" ]; then
echo "File Is Found."
else
echo "File Is Not Found."
fi
Output:

Enrollment No: 2303031241592 Name: R.Dharanidhar reddy

You might also like