0% found this document useful (0 votes)
9 views6 pages

Os PDF

The document outlines practical exercises for a B.Tech Operating System course at Parul Institute of Engineering & Technology. It includes sample codes and aims for various tasks such as printing patterns, finding the largest number, checking file existence, creating child processes, and greeting users based on the time of day. Each practical exercise is accompanied by sample code and expected output.
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)
9 views6 pages

Os PDF

The document outlines practical exercises for a B.Tech Operating System course at Parul Institute of Engineering & Technology. It includes sample codes and aims for various tasks such as printing patterns, finding the largest number, checking file existence, creating child processes, and greeting users based on the time of day. Each practical exercise is accompanied by sample code and expected output.
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/ 6

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy