0% found this document useful (0 votes)
8 views24 pages

Os 0189

The document is a laboratory manual for the Operating Systems course at Parul Institute of Engineering & Technology for B.Tech students in the AI & AIDS program. It includes a certificate of completion for a student, a detailed index of practical exercises, and explanations of basic Linux commands and shell programming concepts. The manual emphasizes the importance of the kernel and shell in operating systems and provides examples of shell scripting and command usage.

Uploaded by

Shinchan Nohara
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)
8 views24 pages

Os 0189

The document is a laboratory manual for the Operating Systems course at Parul Institute of Engineering & Technology for B.Tech students in the AI & AIDS program. It includes a certificate of completion for a student, a detailed index of practical exercises, and explanations of basic Linux commands and shell programming concepts. The manual emphasizes the importance of the kernel and shell in operating systems and provides examples of shell scripting and command usage.

Uploaded by

Shinchan Nohara
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/ 24

Parul institute of Engineering & Technology

Subject Name: Operating System


Subject Code: 303105252
B.Tech ( AI & AIDS) 4h Semester

FACULTY OF ENGINEERING & TECHNOLOGY


BACHELOR OF TECHNOLOGY
OPERATING SYSTEMS LAB
(303105252)

4th SEMESTER
Department of Artificial Intelligence & Data Science

LABORATORY MANUAL 2024-25


Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

CERTIFICATE

This is to certified that Mrs. ALAMURU TOSHITH REDDY


with enrolment No:2303031240189 has successfully completed
his/her laboratory experiments in the OPERATING SYSTEM
(303105252) from the department of AI & AIDS during the
academic year 2024-2025.

Date of Submission: Staff in charge: Dr. Syed Ibad Ali

Head of Department: Dr. Sanjay Agal

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

INDEX

S.no Page Performance Assessment


Title Marks Sign
no. date date

1 Study of Basic commands of Linux.

2 Study the basics of shell programming.

Write a Shell script to print given numbers


3
sum of all digits.

Write a shell script to validate the entered


4
date. (eg. Date format is: dd-mm-yyyy).

Write a shell script to check entered string


5
is palindrome or not.

Write a Shell script to say Good


6 morning/Afternoon/Evening as you log in
to system.

Write a C program to create a child


7
process.

Finding out biggest number from given


8 three numbers supplied as command line
arguments.

9 Printing the patterns using for loop.

Shell script to determine whether given


10
file exist or not.
Write a program for process creation
11
using C. (Use of gcc compiler).
Implementation of FCFS &Round Robin
12
Algorithm.

13 Implementation of Banker's Algorithm.

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
PRACTICAL – 1

Aim: Study of Basic commands of Linux.


Procedure:
1. PWD
• Description: The pwd Linux command prints the current working
directory path, starting from the root (/). Use the pwd command to find
your way in the Linux file system structure maze or to pass the working
directory in a Bash script. In this tutorial, you will learn to use the pwd
command.
• Syntax: pwd

2. CD
• Description: The cd command is used to change the current directory
in both Linux and other Unix-like systems.
• Syntax: cd [directory]

3. LS
• Description: we use ls command to list files and directories. This
command will print all the file and directories in the current directory.
• Syntax: ls [directory]

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

4. CD ..
• Description: This command is used to move to the parent directory of
current directory, or the directory one level up from the current directory.
“..” represents parent directory.
• Syntax: cd ..

5. CAT
• Description: The cat command is a utility command in Linux. One of
its most common usages is to print the content of a file onto the standard
output stream. Other than that, the cat command also allows us to write
some texts into a file.
• Syntax: cat [file-name]

6. HEAD
• Description: The head command, as the name implies, print the top N
number of data of the given input. By default, it prints the first 10 lines

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

of the specified files. If more than one file name is provided then data
from each file is preceded by its file name.
• Syntax: head [option] [file]

7. TAIL
• Description: Tail is a command which prints the last few numbers of
lines (10 lines by default) of a certain file, then terminates. By default,
“tail” prints the last 10 lines of a file, then exits. as you can see, this
prints the last 10 lines of /var/log/messages.
• Syntax: tail [option] [file]

8. MKDIR
• Description: The mkdir command in Linux/Unix allows users to create
or make new directories. mkdir stands for “make directory.” With mkdir
, you can also set permissions, create multiple directories (folders) at
once, and much more.
• Syntax: mkdir [directory name]

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

9. MV
• Description: The mv command termed as “Move”, which is a
command-line utility to move files or directories from source to target.
It supports the moving of a single file, multiple files, and directories.
• Syntax: mv [option] source destination

10. CP
• Description: cp command copies files (or, optionally, directories). The
copy is completely independent of the original. You can either copy one
file to another, or copy arbitrarily many files to a destination directory.
In the first format, when two file names are given, cp command copies
SOURCE file to DEST file.
• Syntax: cp [option] source destination

11. RMDIR
• Description: mdir command is used remove empty directories from the
filesystem in Linux. The rmdir command removes each and every
directory specified in the command line only if these directories are
empty. So if the specified directory has some directories or files in it
then this cannot be removed by rmdir command.
Student Name: ALAMURU TOSHITH REDDY
Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

• Syntax: rmdir [directory name]

12. GEDIT
• Description: The gedit command is used to create and open a file
• Syntax: gedit filename.txt

13. MAN
• Description: man command in Linux is used to display the user manual
of any command that we can run on the terminal. It provides a detailed
view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES,
ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS
• Syntax: man command

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

14. ECHO

• Description: Display text on the screen


• Syntax: Display text on the screen

15. CLEAR

• Description: Used to clear the screen


• Syntax: clear

16. WHOAMI
• Description: whoami prints the effective user ID. This command
prints the username associated with the current effective user ID
• Syntax: whoami [option]

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

17. WC
• Description: wc (word count) command, can return the number of
lines, words, and characters in a file.
• Syntax: wc [option]… [file]…
Example:
✓ Print the byte counts of file myfile.txt
wc -c myfile.txt
✓ Print the line counts of file myfile.tx
wc -l myfile.txt
✓ Print the word counts of file myfile.txt
wc -w myfile.txt

18. GREP
• Description: grep command uses a search term to look through a file
• Syntax: grep [option]… Pattern [file]

19. FREE
• Description: To display the RAM details in Linux machine need to
write following command.
• Syntax: free

20. PIPE (|)


Student Name: ALAMURU TOSHITH REDDY
Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
• Description: Pipe command is used to send output of one program as
a input to another. Pipes “|” help combine 2 or more commands
• Syntax: Command 1 | command 2

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
PRACTICAL – 2

Aim: Study the basics of Shell programming.


What is a Shell?
It is a list of commands in a computer program that is run by the Unix shell which is a
command line interpreter. A shell script usually has comments that describe the steps.
An Operating is made of many components,
But its two prime components are –
✓ Kernel
✓ Shell

A Kernel is at the nucleus of a computer. It makes the communication between the


hardware and software possible. While the Kernel is the innermost part of an operating system,
a shell is the outermost one. A shell in a Linux operating system takes input from you in the
form of commands, processes it, and then gives an output. It is the interface through which a
user works on the programs, commands, and scripts. A shell is accessed by a terminal which
runs it. When you run the terminal, the Shell issues a command prompt (usually $), where you
can type your input, which is then executed when you hit the Enter key. The output or the result
is thereafter displayed on the terminal. The Shell wraps around the delicate interior of an
Operating system protecting it from accidental damage. Hence the name Shell.

Types Of Shells:
1. Bournee shell: This is default shell for version 7 unix. The character $ is the
default prompt for the bourne shell.
2. C shell: This is a unix shell and a command processor that is run in a text window
. The character % is the default prompt for the C shell. File commands can also be
read easily by the C shell , which is known as a script.

How to create file in linux:


In Linux there are two commands which are used to create the files in Linux:
1. Gedit
2. nano

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

What is Shell Scripting?

Shell scripting is writing a series of command for the shell to execute. It can combine
lengthy and repetitive sequences of commands into a single and simple script, which can be
stored and executed anytime. This reduces the effort required by the end user. Let us understand
the steps in creating a Shell Script
1. Create a file using a vi editor(or any other editor). Name script file with extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh
"#!" is an operator called shebang which directs the script to the interpreter location. So, if we
use"#! /bin/sh" the script gets directed to the bourne-shell. Let's create a small script -

Let's create a small script –

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

#!/bin/sh
ls
Let's see the steps to create it –
Command 'ls' is executed when we execute the scrip sample.sh file.

Adding shell comments


Commenting is important in any program. In Shell programming, the syntax to add a
comment is
#comment
Let understand this with an example.

What are Shell Variables?


As discussed earlier, Variables store data in the form of characters and numbers.
Similarly, Shell variables are used to store information and they can by the shell only.
For example, the following creates a shell variable and then prints it:
variable ="Hello"
echo $variable

Below is a small script which will use a variable.

#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Let's understand, the steps to create and execute the script

As you see, the program picked the value of the variable 'name' as Joy and 'remark' as
excellent.
This is a simple script. You can develop advanced scripts which contain conditional
statements, loops, and functions. Shell scripting will make your life easy and Linux
administration a breeze.
Summary:
• Kernel is the nucleus of the operating systems, and it communicates between
hardware and software
• Shell is a program which interprets user commands through CLI like Terminal
• The Bourne shell and the C shell are the most used shells in Linux
• Shell scripting is writing a series of command for the shell to execute
• Shell variables store the value of a string or a number for the shell to read
• Shell scripting can help you create complex programs containing conditional
statements, loops, and functions .

These two commands are useful to create the files.

1. Gedit:
Syntax : gedit prac1.txt
Description: Gedit, the deafault GUI editor if you use Gnome ,also runs under KDE and
other desktops . Most gNewsense and linux installations use gnome by default. To start
Gedit open a terminal and type.

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
After Gedit command function a new window will open in that we have to give input.
After giving input we have save the file and after that use command bash.

2. Bash:
Syntax : bash prac11.sh
Description : it is used to read the data in existing file in the linux .

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL –3

Aim: Write a Shell script to print given numbers sum of all digits.
Sample Code:
#!/bin/bash echo "Enter the first number:"
read num1 echo "Enter the second number:"
read num2 sum=$((num1 + num2))
echo "The sum of $num1 and $num2 is: $sum"

Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 4

Aim: Write a shell script to validate the entered date.


(eg. Date format is: dd-mm-yyyy).

Sample Code:
#!/bin/bash
# Function to validate date format
validate_date() {
date -d "$1" 2>/dev/null
if [ $? -eq 0 ]; then
return 0 # Valid date
else
return 1 # Invalid date
fi
}
# Read date from user input
read -p "Enter a date in the format dd-mm-yyyy: "
date_input
# Validate the date format
if validate_date "$date_input"; then
echo "Valid date: $date_input"
else
echo "Invalid date format. Please enter a date in the
format dd-mm-yyyy."
fi
Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 5

Aim: Write a shell script to print whether the number is palindrome or not?
Sample Code:
#!/bin/bash
# Function to check if a string is a palindrome
is_palindrome() {
local original_string="$1"
$1 represents the first argument passed to a script or function.
local reversed_string=$(rev <<< "$original_string")
if [[ "$original_string" == "$reversed_string" ]]; then
return 0 # Palindrome
else
return 1 # Not a palindrome
fi
}
# Read input from user
read -p "Enter a string: " string
# Check if the string is a palindrome
if is_palindrome "$string"; then
echo "'$string' is a palindrome."
else
echo "'$string' is not a palindrome."
fi
Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 6

Aim: Write a Shell script to say Good morning/Afternoon/Evening as you log


in to system.

Sample Code:

#!/bin/bash
# Get the current hour
current_hour=$(date +%H)
(current_hour=$(date +%H):
# Determine the greeting
if [ "$current_hour" -lt "12" ]; then
(if [ "$current_hour" -lt "12" ]; then
echo "Good Morning!"
elif [ "$current_hour" -ge "12" ] && [
"$current_hour" -lt "18" ]; then
(elif [ "$current_hour" -ge "12" ] && [
"$current_hour" -lt "18" ]; then: This line checks
If

echo "Good Afternoon!"


else
echo "Good Evening!"
fi

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 7.1

Aim: To generate multiple child process

Sample Code:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;
}

Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 7.2

Aim: To Generate Process id for 2 Processors

Sample Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// make two process which run same
// program after this instruction
pid_t p = fork();
if(p<0){
perror("fork fail");
exit(1);
}
printf("Hello world!, process_id(pid) = %d \n",getpid());
return 0;
}

Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189
0
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester

PRACTICAL – 8

Aim: C Program to find the maximum of three numbers

Sample Code:
#include <stdio.h>
int main() {
int a = 11, b = 2, c = 9;
// Finding max using compound expressions
if (a >= b && a >= c)
printf("%d is the largest number.", a);
else if (b >= a && b >= c)
printf("%d is the largest number.", b);
else
printf("%d is the largest number.", c);
return 0;
}

Output:

Student Name: ALAMURU TOSHITH REDDY


Student Enroll No:2303031240189

You might also like