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