Amity Os File
Amity Os File
SESSION:2023-2024
Practical File
On
Operating System
B.Tech 4CSE10X
Lab Practical 1
Commands:
1. pwd: This command is used to display the location of the current working
directory, in which we are operating, i.e. in which the terminal is open, and is
useful when directory changes are made frequently.
Syntax of the command: $ pwd
2. ls: This command is used to list down all the directories and files inside the
present working directory. If the path is removed, ls command shows the
current working directory’s content.
Syntax of the command: $ ls
3. mkdir :The mkdir command is used to create a new directory under any
directory.
6. touch: This command can be used to create a new file. We can create
multiple empty files by executing it once, and can be used to generate and
modify timestamp of any file.
Syntax of the command: $ touch file1.txt
11.head: This command prints the first ten lines of a text file and displays
the content of a file. The command given below helps to print the first ten
lines of the “file1.txt” file.
Syntax of the command: $ head file1.txt
12. tail: This command prints the last ten lines of a text file and is useful for
reading the error message. The command given below helps to print the
ten lines from the bottom of “file1.txt” file.
Syntax of the command: $ tail file1.txt
13. grep: This is a useful command and is used to search for matching
patterns in a file. This command prints all lines containing the matching
strings. The command given below prints all the lines that contain “20”
from “file1.txt”.
Syntax of the command: $ cat file1.txt | grep 20
14. sed: This command is also known as stream editor. It is used to edit files
using a regular expression. This lets us to find, replace, and delete
patterns in a file without using a text editor.
Syntax of the command: $ sed
15. tac: This displays the file content in the reverse order. This prints the last
line first, then the second last and so on.
Syntax of the command: $ tac
16. more: This command is used to view the text files in the command
prompt, displaying one screen at a time in case the file is large. This
allows the user to scroll up and down through the page.
Syntax of the command: $ more
17. less: This command is used to read the contents of a file one page(one
screen) at a time.
Syntax of the command: $ less
18. id: This command is used to find out the user and group names, and,
numeric IDs of the current user or any other user in the server. This
command is mainly used for user management in a server.
Syntax of the command: $ id
19. cut: This command retrieves sections from a file and prints the result
as Terminal outputs. This is used to remove sections from each line of
files and print specific parts of lines from each file to standard output.
This is used to select a specific column of a file.
Syntax of the command: $ cut
20. sort: This command is used to sort the contents of a file in numeric or
alphabetical order, and print the results to standard output(usually the
terminal screen).
Syntax of the command: $ sort
21. find: This command is used to find a particular file within a directory. It
is used to find the list of files for the various conditions like permission,
user ownership, modification, date/time, size, and more.
Syntax of the command: $ find
22. ps: This command is used to view currently running processes on the
system and to display some process information.
Syntax of the command: $ ps
Syntax:
Syntax: clear
25. cal:The cal command is used to display the current month's calendar with the
current date highlighted.
Syntax: cal
Lab Practical 2
Commands:
3.Jobs Command : Jobs command is used to list the jobs that you are running
in the background and in the foreground.
Syntax: jobs [JOB]
Command: $ jobs
5.Ps command: The `ps` command, which stands for “process status,” is like a
computer tool that helps you see what’s happening inside your Linux computer.
The ps command provides a snapshot of the current processes on your system.
Syntax: ps [options]
9.Append Redirection: With the help of this Redirection, you can append the
output to the file without compromising the existing data of the file.
“>>” standard output
“<<” standard input
10.Pipe Operator: The pipe operator is the | character (typically located above
the enter key). This operator serves to join the standard output stream from one
process to the standard input stream of another process
Lab Practical 3
Aim: Write a program to implement First come First serve CPU scheduling
algorithm
Language used :C
Code:
#include <stdio.h>
#include <stdlib.h>
// Function prototypes
void input(struct Process*, int);
void calc(struct Process*, int);
void show(struct Process*, int);
void sort(struct Process*, int);
int main() {
int n;
printf("\nEnter the number of processes in your system:\n");
scanf("%d", &n);
input(p, n);
sort(p, n);
calc(p, n);
show(p, n);
// Calculate and display average waiting time and average turnaround time
float avgWT = 0, avgTAT = 0;
for (int i = 0; i < n; i++) {
avgWT += p[i].wt;
avgTAT += p[i].tat;
}
avgWT /= n;
avgTAT /= n;
// Display function
void show(struct Process *p, int n) {
printf("\nProcess\tArrival Time\tBurst Time\tWaiting Time \tTurn Around Time\n");
for (int i = 0; i < n; i++) {
printf(" P[%d]\t %d\t\t%d\t\t%d\t\t %d\n", p[i].id, p[i].at, p[i].bt, p[i].wt, p[i].tat);
}
}
Output:
Lab Practical 4
Aim: Write a program to implement Shortest Job First (SJF) CPU scheduling
algorithm
Language used :C
Code:
#include <stdio.h>
int main() {
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time.
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
avg_wt = (float)total / n;
total = 0;
printf("P\tBT\tWT\tTAT\n");
// Calculation of Turn Around Time and printing the data in table format.
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d\t%d\t%d\t%d\n", A[i][0], A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
printf("Average Waiting Time= %f\n", avg_wt);
printf("Average Turnaround Time= %f\n", avg_tat);
return 0;
}
Output:
Lab Practical 5
Language used :C
Code:
#include <stdio.h>
#include <stdlib.h>
struct Process {
int pid; // Process ID
int bt; // CPU Burst time required
int priority; // Priority of this process
};
findavgTime(proc, n);
}
int main() {
int n;
priorityScheduling(proc, n);
return 0;}
Output:
Lab Practical 6
Language used :C
Code:
#include<stdio.h>
// Execute the process for the quantum time or the remaining time, whichever is smaller
if (processes[i].remaining_time > quantum) {
time += quantum;
processes[i].remaining_time -= quantum;
} else {
time += processes[i].remaining_time;
processes[i].remaining_time = 0;
printf("Process %d is completed at time %d\n", processes[i].id, time);
}
}
}
int main() {
int n, quantum;
return 0;
}
Output: