Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
PRACTICAL –9
Aim: Printing the patterns using for loop
Sample Code:
echo "Printing a pattern of $largest rows:"
for ((i=1; i<=largest; i++))
do
for ((j=1; j<=i; j++))
do
echo -n "* "
don
e
echo
done
Output:
daksh
daksh
daksh
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
PRACTICAL – 8
Aim: Finding out biggest number from given three numbers supplied as
command line arguments.
Sample Code:
#!/bin/bash
echo "Enter the first number:"
read num1
echo "Enter the second number:"
read num2
echo "Enter the third number:"
read num3
if [[ $num1 -ge $num2 && $num1 -ge $num3 ]]
then
echo "The largest number is $num1"
elif [[ $num2 -ge $num1 && $num2 -ge $num3 ]]
then
echo "The largest number is $num2"
else
echo "The largest number is $num3"
fi
Output:
daksh
daksh
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
PRACTICAL – 10
Aim: Shell script to determine whether given file exist or not.
Sample Code:
fileExists() {
if [ -e "$1" ]; then
echo "File exists."
else
echo "File does not exist."
fi
}
fileExists "yourfile.txt"
Output:
daksh
daksh
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
PRACTICAL – 7
Aim: Write a C program to create a child process.
Sample Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
printf("Simulating process creation.\n");
pid_t pid = fork(); // Create a child process
if (pid < 0) {
// Fork failed
perror("Fork failed");
return 1;
} else if (pid == 0) {
// Child process
printf("This is the child process.\n");
printf("Simulated Child Process ID: %d\n", getpid());
} else {
// Parent process
printf("This is the parent process.\n");
printf("Simulated Parent Process ID: %d\n", getpid());
printf("Simulated Child Process ID: %d\n", pid);
printf("Waiting for the child process to complete...\n");
wait(NULL); // Wait for the child process to complete
printf("Child process has completed.\n");
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
}
return 0;
}
Output:
Parul institute of Engineering & Technology
Subject Name: Operating System
Subject Code: 303105252
B.Tech (AI & AIDS) 4th Semester
Enrollment No :- 2303031240568
PRACTICAL – 6
Aim: Write a Shell script to say Good morning/Afternoon/Evening as you log in
to system.
Sample Code:
current_time=$(date +%H)
if [ $current_time -lt 12 ]; then
echo "Good morning!"
elif [ $current_time -lt 17 ]; then
echo "Good afternoon!"
else
echo "Good evening";
fi
Output:
daksh
daksh