Operating System Lab
Operating System Lab
OPERATING SYSTEM
COURSE CODE : R1UC403B
ADMISSION NO : 23SCSE1010470
SEC : 46
SUBMITTED TO:
EXPERIMENT -1
1.ls
Syntax:ls[options][directory]
Lists all files and directories within the specified directory. If no directory is given, it
shows the contents of the current working directory. Various options can be used to
display hidden files, detailed info, or sort the output.
2.cd
Syntax:cd[directory_path]
Changes the current directory to the specified path. It allows navigation through the file
system, such as moving into a folder, going up one level, or switching to the home
directory.
3.pwd
Syntax:pwd
Displays the full absolute path of your current working directory. It's useful for
understanding where you are in the directory structure, especially after moving around
with cd.
4.mkdir
Syntax:mkdir[directory_name]
Creates a new directory with the given name at the current location or specified path. It
helps in organizing files by creating folders for them.
5.rm
Syntax:rm[options][file_or_directory]
Deletes files or directories from the system. This command removes them permanently
and cannot be undone without backup. Use options like -r for recursive deletion and -f to
force deletion.
6.cp
Syntax:cp[options][source][destination]
Copies files or directories from one location to another. It preserves the original while
making a duplicate at the destination. Use the -r option to copy entire directories.
7.mv
Syntax:mv[source][destination]
Moves files or directories from one place to another. It is also used to rename files by
specifying a new name as the destination.
8.touch
Syntax:touch[file_name]
Creates a new, empty file with the given name. If the file already exists, it updates the
file’s last modified timestamp without changing the content.
9.cat
Syntax:cat[file_name]
Displays the content of a text file directly in the terminal. It can also be used to
concatenate multiple files and show their combined content.
10.clear
Syntax:clear
Clears all previous output from the terminal window, giving you a clean screen to work
with. It does not affect running programs or files.
11.chmod
Syntax:chmod[options][permissions][file_or_directory]
Changes the permission settings of a file or directory. Permissions control who can read, write, or
execute a file. Permissions can be set numerically (e.g. chmod 755) or symbolically (e.g. chmod
u+x).
EXPERIMENT - 2
Bash stand for BOURNE AGAIN SHELL . It is a command line interpreter or shell
commonly used on Unix and Linux system . It allows user to interact with the operating
system by typing commands.
Code:
#!/bin/bash
# Read number from user
echo "Enter a number:"
read number
# Check if the number is even or odd using modulus
if [ $((number % 2)) -eq 0 ]
then
echo "$number is Even"
else
echo "$number is Odd"
fi
Output:
EXPERIMENT - 3
#!/bin/bash
echo "Enter first number:"
read a
echo "Enter second number:"
read b
# Swapping using a temp variable
temp=$a
a=$b
b=$temp
echo "After swapping:"
echo "First number: $a"
echo "Second number: $b"
Output:
EXPERIMENT – 4
#!/bin/bash
Output:
EXPERIMENT – 5
#!/bin/bash
a=0
b=1
Output:
EXPERIMENT – 6
AIM : Write a C program using the following system calls (fork, exec).
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
// Child process
printf("Child process: executing 'ls'\n");
execl("/bin/ls", "ls", "-l", NULL);
} else {
// Parent process
printf("Parent process: PID = %d\n", pid);
}
return 0;
}
Output:
EXPERIMENT – 7
AIM : Write a C program using the following system calls (get_pid, exit).
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main() {
printf("Process ID: %d\n", getpid());
printf("Exiting the program.\n");
exit(0);
}
Output:
EXPERIMENT – 8
AIM : Write a C program using the I/O system calls (open, read, write, etc)
Code
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int fd;
char buffer[100];
fd = open("input.txt", O_RDONLY);
if (fd < 0) {
perror("Error opening file");
return 1;
}
read(fd, buffer, sizeof(buffer));
write(1, buffer, sizeof(buffer)); // write to stdout
close(fd);
return 0;
}
Output:
EXPERIMENT – 9
int main() {
int n;
printf("Enter number of processes: ");
scanf("%d", &n);
struct Process proc[n];
for (int i = 0; i < n; i++) {
proc[i].id = i + 1;
printf("Enter burst time for process %d: ", i + 1);
scanf("%d", &proc[i].burst_time);
}
FCFS(proc, n);
printProcessInfo(proc, n);
return 0;
}
#include <stdio.h>
struct Process {
int id;
int burst_time;
int waiting_time;
int turnaround_time;
};
void SJF(struct Process proc[], int n) {
struct Process temp;
// Sort processes by burst time
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (proc[i].burst_time > proc[j].burst_time) {
temp = proc[i];
proc[i] = proc[j];
proc[j] = temp;
}
}
}
proc[0].waiting_time = 0;
proc[0].turnaround_time = proc[0].burst_time;
for (int i = 1; i < n; i++) {
proc[i].waiting_time = proc[i - 1].waiting_time + proc[i - 1].burst_time;
proc[i].turnaround_time = proc[i].waiting_time + proc[i].burst_time;
}
}
void printProcessInfo(struct Process proc[], int n) {
printf("ProcessID\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (int i = 0; i < n; i++) {
printf("%d\t\t%d\t\t%d\t\t%d\n", proc[i].id, proc[i].burst_time, proc[i].waiting_time,
proc[i].turnaround_time);
}
}
int main() {
int n;
printf("Enter number of processes: ");
scanf("%d", &n);
struct Process proc[n];
for (int i = 0; i < n; i++) {
proc[i].id = i + 1;
printf("Enter burst time for process %d: ", i + 1);
scanf("%d", &proc[i].burst_time);
}
SJF(proc, n);
printProcessInfo(proc, n);
return 0;
}
#include <stdio.h>
struct Process {
int id;
int burst_time;
int remaining_time;
int waiting_time;
int turnaround_time;
};
int main() {
int n, quantum;
RoundRobin(proc, n, quantum);
printProcessInfo(proc, n);
return 0;
}