Os Final Lab Meet
Os Final Lab Meet
Operating System(303105252)
B-Tech CSE 4th sem and 2nd Year
PRACTICAL -1
Aim – Study the basics of Linux Command
What is Linux
?
Linux is an open-source, Unix-like operating system kernel that serves as the foundation for
many operating systems, known as Linux distributions or distros. It was created by Linus
Torvalds in 1991 and has since become one of the most widely used operating systems in the
world, especially in servers, embedded systems, and desktop environments.
1. Pwd : This command in Unix/Linux systems is used to display the full path of
the current working directory in the terminal.
directory.
4. Ls –ltr : It is used to list the contents of a directory in long format (-l), sorted by
modification time (-t), and in reverse order (-r). This means the oldest files are
displayed first.
6. Date : The date command displays the current date and time.
• +%H : To display the hour in 24-hour format (00-23).
• +%M : To display the minute of the current time (00-59).
• +%H:%M:%S : To displays the current time in the format
of hour:minute:second (24-hour format).
• +%A : To display the full name of the weekday (e.g., Sunday, Monday, etc.).
• +%D : To display the date in MM/DD/YY format (month/day/year).
• +%Y / +%G : Both displays the year in four-digit format.
• +%h : To display the abbreviated month name (e.g., Jan, Feb, Mar, etc.).
• +%m : To display the month as a two-digit number (01-12).
• +%d : To display the day of the month as a two-digit number (01-31). • +%y
/+%g : To display the last two digits of the year.
9. Touch : This touch command is used to create empty files or update the timestamp
of existing files.
11. Cat : It is used to display the contents of a file, combine multiple files, or create a
new file.
12. Clear : It is used to clear the terminal screen.
13. Echo : It is used to display a line of text or output the value of a variable to
the terminal.
PRACTICAL – 2
Aim – Study the basics of Shell
What is a shell ? Programming
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 results
is the 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 Shell:
1. Bottom shell
2. C Shell
1. Create a file using a vi editor (or any other editor). Name script file with extension .sh 2.
“ #! ” 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.
1. Touch command
2. Cat command
3. Text editor
PRACTICAL -3
Aim – Write a Shell script to Print given numbers Sum of all Digits.
Program Code:
Output:
Practical No. 4
Aim: Write a shell script to validate the entered date.
(eg. date format is: dd-mm-yyyy).
Program Code:
#!/bin/bash
echo "$d/$m/$y"
Practical no. 5
Aim: Write a shell script to print whether the number is palindrome or not
Program Code:
while [ $a -ne 0 ]; do
b=$((a % 10))
sum=$((sum * 10 + b))
a=$((a / 10))
done
echo "$sum"
Output:
Practical no. 6
Aim: Write a shell script to say Good morning/ Good afternoon/ good evening
as you log in to system.
Program Code:
current_time=$(date +%H)
else
fi
Output:
Practical no. 7
Program Code:
#include <stdio.h>
#include <windows.h>
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(
NULL,
"cmd /c echo Child Process Running",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi)
){
printf("CreateProcess failed (%d).\n", GetLastError());
return 1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
Output:
Practical no. 8
Aim: Finding the biggest number from given three numbers supplied as command
line arguments.
Program Code:
echo "Enter the first number "
read a
echo "Enter the second number"
read b
echo "Enter the third number"
read c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "First number is greater "
elif [ $b -gt $a ] && [ $b -gt $c ]
then
echo "Second number is greater "
else
echo "Third number is greater "
fi
Output:
Practical no. 9
#!/bin/bash
rows=5
Output:
Practical no. 10
Program Code:
#!/bin/bash
if [ -e "$filename" ]; then
echo "File '$filename' exists."
else
echo "File '$filename' does not exist."
fi
Output:
Practical no. 11
Aim: Write a program for process creation using C. (Use of gcc compiler)
Program Code:
#include <stdio.h>
#include <windows.h>
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(
NULL,
"cmd /c echo Child Process Running",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi)
){
printf("CreateProcess failed (%d).\n", GetLastError());
return 1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
Output:
Practical no. 12
Program Code:
#include <stdio.h>
void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
}
int t = 0;
while (1) {
int done = 1;
for (int i = 0; i < n; i++) {
if (rem_bt[i] > 0) {
done = 0;
if (rem_bt[i] > quantum) {
t += quantum;
rem_bt[i] -= quantum;
} else {
Name: Meet Madhani
Enrolment no: 2403031057044 18
Faculty of Engineering and Technology
Operating System(303105252)
B-Tech CSE 4th sem and 2nd Year
t += rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
}
}
}
if (done == 1)
break;
}
int main() {
int processes[] = {1, 2, 3};
int n = sizeof(processes) / sizeof(processes[0]);
int burst_time[] = {10, 5, 8};
int quantum = 2;
printf("FCFS Scheduling:\n");
findAvgTimeFCFS(processes, n, burst_time);
return 0;
}
Output:
Practical no. 13
#include <stdio.h>
#include <stdbool.h>
bool isSafe(int processes[], int avail[], int max[][10], int alloc[][10], int P, int R) {
int need[P][10];
calculateNeed(need, max, alloc, P, R);
bool finish[P];
int safeSeq[P], work[10];
for (int i = 0; i < P; i++) finish[i] = false;
for (int i = 0; i < R; i++) work[i] = avail[i];
int count = 0;
while (count < P) {
bool found = false;
for (int p = 0; p < P; p++) {
if (!finish[p]) {
int j;
for (j = 0; j < R; j++)
if (need[p][j] > work[j])
break;
if (j == R) {
for (int k = 0; k < R; k++)
work[k] += alloc[p][k];
safeSeq[count++] = processes[p];
finish[p] = true;
found = true;
}
}
}
if (!found) {
printf("\nUnsafe State\n");
return false;
}
}
Name: Meet Madhani
Enrolment no: 2403031057044 21
Faculty of Engineering and Technology
Operating System(303105252)
B-Tech CSE 4th sem and 2nd Year
int main() {
int P, R;
printf("Enter number of processes: ");
scanf("%d", &P);
printf("Enter number of resources: ");
scanf("%d", &R);
return 0;
}
Output: