Professional Documents
Culture Documents
LAB ASSIGNMENT 1
1. What is operating system & explain features of operating system?
Operating System is a fully integrated set of specialized programs that handle all the operations of the
computer. It controls and monitors the execution of all other programs that reside in the computer,
which also includes application programs and other system software of the computer. Examples of
Operating Systems are Windows, Linux, Mac OS, etc..
Definition:
An Operating System (OS) is an interface between a computer user and computer hardware.
An operating system is a software which performs all the basic tasks like file management,
memory management, process management, handling input and output, and controlling
peripheral devices such as disk drives and printers.
An Operating System (OS) is a collection of software that manages computer hardware
resources and provides common services for computer programs. The operating system is the
most important type of system software in a computer system.
The operating system helps in improving the computer software as well as hardware. Without
OS, it became very difficult for any application to be user-friendly.
The Operating System provides a user with an interface that makes any application attractive
and user-friendly.
The operating System comes with a large number of device drivers that make OS services
reachable to the hardware environment and Each and every application present in the system
requires the Operating System.
The operating system works as a communication channel between system hardware and
system software.
The operating system helps an application with the hardware part without knowing about the
actual hardware configuration.
It is one of the most important parts of the system and hence it is present in every device,
whether large or small device.
Functions Of Operating System
1. Memory Management –
The Primary Memory or Main Memory is controlled by the operating system. Each byte or word in
main memory has an address, and the array of bytes or words is quite big. The CPU may immediately
access main memory, which is a quick form of storage. A programme must first be loaded in the main
memory before it can be executed. The following tasks are carried out by an operating system to
manage memory: It keeps track of the primary memory, or the number of bytes of memory that each
user programme is using. the addresses of the memory that has already been assigned and the
addresses of the memory that is still available. In multiprogramming, the OS determines the order and
Page no.1
Khushi Sahu 0801CA231074
duration of memory access for each process. After a process requests memory, it allocates that
memory to that process, and when that process has finished or is engaged in I/O activity, it deallocates
that memory.
2. Security –
An Operating System aids you in achieving your goal of keeping your data secure in today's society.
An operating system's capability increases its stability. An operating system makes use of firewalls to
guard against and stop outside attacks. The system can only be used by people who have been given
permission to do so.
3. Job accounting –
Operating system keeps track of the amount of time and resources each job and user uses; this data
can be used to monitor how much of each resource is being used by a specific user or group of users.
4. Process Management -
The OS controls the order in which processes access the processor and how much processing time
each process receives in a multi-programming environment. Process scheduling is the name of this OS
feature. The following tasks are handled by an operating system in terms of processor management.
1)monitors the state of the processes.
2)The programme that carries out this function is referred to as a traffic controller.
3)gives a process access to a CPU that is a processor.
4)When a process is no longer necessary, the processor is de-allocated.
5. Device Management –
Device communication is controlled by an OS using the appropriate drivers. The operating system
handles the following tasks for device management.
1) Keeping track of all the system's linked gadgets.
2) The input/output controller is a software that is designated by the operating system as being in
charge of each device.
3) It determines which process has access to each device and how long it has that access.
4) When devices are no longer needed, it de-allocates them in an effective and efficient manner.
6. File Management –
Files are where data is saved. We can create, edit, update, and delete files with the aid of an operating
system. Additionally, it facilitates file transfers across devices. The physical entities that are stored on
the hardware are seen as files.
Directories are used to structure a file system and make it easier to navigate and use. These directories
might include additional directories and files. The following file management tasks are performed by
an operating system. It keeps track of information storage locations, user access preferences, file
status, and more. The file system refers to these resources in general.
7.Coordination between other software and users –
Between the user and the system hardware, the operating system acts as a bridge.
As needed by the user, it organises and allocates tasks to various components of the software, such as
interpreters, compilers, etc.
9. Networking –
Networking highly depends on operating systems. Distributed systems are a typical example, where a
server OS can guarantee consistency among the distributed PCs.
The operating system in such a system enables the connection of several independent and
geographically dispersed computers via a single communication channel.
10. Understanding Commands –
Page no.2
Khushi Sahu 0801CA231074
As a user, you enter commands in such a language that you understand. Because the computer
primarily understands 0s and 1s (binary language), the operating system handles command
interpretation and then directs the resources to process them.
1.Kernel: Kernel is the core of the Linux based operating system. It virtualizes the common
hardware resources of the computer to provide each process with its virtual resources. This makes
the process seem as if it is the sole process running on the machine. The kernel is also responsible
for preventing and mitigating conflicts between different processes. Different types of the kernel
are:
Page no.3
Khushi Sahu 0801CA231074
Monolithic Kernel
Hybrid kernels
Exo kernels
Micro kernels
2.System Library: Linux uses system libraries, also known as shared libraries, to implement
various functionalities of the operating system. These libraries contain pre-written code that
applications can use to perform specific tasks. By using these libraries, developers can save time
and effort, as they don’t need to write the same code repeatedly. System libraries act as an interface
between applications and the kernel, providing a standardized and efficient way for applications to
interact with the underlying system.
3.Shell: The shell is the user interface of the Linux Operating System. It allows users to interact
with the system by entering commands, which the shell interprets and executes. The shell serves as
a bridge between the user and the kernel, forwarding the user’s requests to the kernel for
processing. It provides a convenient way for users to perform various tasks, such as running
programs, managing files, and configuring the system.
4.Hardware Layer: The hardware layer encompasses all the physical components of the computer,
such as RAM (Random Access Memory), HDD (Hard Disk Drive), CPU (Central Processing Unit),
and input/output devices. This layer is responsible for interacting with the Linux Operating System
and providing the necessary resources for the system and applications to function properly. The
Linux kernel and system libraries enable communication and control over these hardware
components, ensuring that they work harmoniously together.
5.System Utility: System utilities are essential tools and programs provided by the Linux Operating
System to manage and configure various aspects of the system. These utilities perform tasks such as
installing software, configuring network settings, monitoring system performance, managing users
and permissions, and much more. System utilities simplify system administration tasks, making it
easier for users to maintain their Linux systems efficiently.
1.Download VirtualBox:
Go to the VirtualBox website: https://www.virtualbox.org/
Download and install VirtualBox for your operating system (Windows, macOS, Linux).
Page no.4
Khushi Sahu 0801CA231074
6.Install Ubuntu:
Select "Install Ubuntu" from the boot menu.
Follow the on-screen instructions to choose language, keyboard layout, and other settings.
When prompted, choose installation type. You can select "Erase disk and install Ubuntu" for a simple
setup, or choose manual partitioning for advanced users.
Create a user account and set up password.
Wait for the installation to complete.
9.Explore Ubuntu:
Congratulations! You've successfully installed Ubuntu Linux on your virtual machine. You can now
explore the Ubuntu desktop environment, install software, and perform various tasks.
Remember, this guide is specific to VirtualBox and Ubuntu, but the general steps are similar for other
virtualization software and Linux distributions. Make sure to refer to the documentation specific to the
software and distribution you choose for installation.
2. Hardware Compatibility:
Page no.5
Khushi Sahu 0801CA231074
Windows: Widely compatible with a vast array of hardware configurations due to its extensive
driver support.
macOS: Limited to Apple hardware, ensuring tight integration and optimized performance.
Linux: Supports a broad range of hardware, including older and specialized hardware, thanks to
extensive community-driven driver development.
Unix: Hardware compatibility varies depending on the Unix-based system and its target hardware.
3. Software Availability:
Windows: Offers a vast selection of commercial and free software, with extensive support for
popular applications and games.
macOS: Provides access to a curated selection of software through the Mac App Store and third-
party developers, with a focus on quality and security.
Linux: Offers a wide range of free and open-source software through package managers and
repositories, though support for commercial software varies.
Unix: Software availability depends on the specific Unix variant and its ecosystem, with many
Unix-based systems focusing on server and enterprise applications.
4.Security:
Windows: Historically criticized for security vulnerabilities, though recent versions have
improved security features such as Windows Defender and User Account Control (UAC).
macOS: Generally considered more secure due to its Unix-based architecture, sandboxing of
applications, and stringent app store review process.
Linux: Known for its robust security features, including user permissions, access control lists
(ACLs), and security-focused distributions like SELinux and AppArmor.
Unix: Offers strong security foundations, particularly in multi-user environments, with features
like file permissions and access controls.
6.Cost:
Windows: Typically requires a license fee for commercial versions, though some versions may be
available for free for certain users (e.g., Windows 10 for education).
macOS: Included with the purchase of Apple hardware, with periodic upgrades available at no
additional cost.
Linux: Generally available for free, with many distributions offering free updates and support.
However, commercial support options are also available for some distributions.
Unix: Cost varies depending on the specific Unix variant and the support services required.
This comparison provides a broad overview, but the suitability of an operating system depends on
individual needs, preferences, and use cases. Additionally, each operating system continues to evolve,
with new features and improvements shaping the landscape over time.
Page no.6
Khushi Sahu 0801CA231074
6.What are the internal commands. Explain it? Give 10 commands with
syntax and examples (with screenshots)?
Internal commands, also known as built-in commands, are commands that are directly built into the
shell (command-line interpreter) itself rather than being separate executable files located in directories
listed in the system's PATH variable. These commands are usually simple and perform basic
operations, such as file manipulation, text processing, and system configuration.
Here are 10 internal commands commonly available in Unix/Linux shells like Bash, along with their
syntax and examples:
1. cd (Change Directory):
Syntax: cd [directory]
Example: cd Documents
Description: Changes the current working directory to the specified directory.
3. echo (Echo):
Syntax: echo [arguments]
Example: echo Hello, World!
Page no.7
Khushi Sahu 0801CA231074
5. alias (Alias):
Syntax: alias [name]='[command]'
Example: alias ll='ls -l'
Description: Creates an alias for a command or command sequence.
6. exit (Exit):
Syntax: exit
Example: exit
Description: Exits the current shell or terminal session.
7. export (Export):
Syntax: export [variable]=[value]
Example: export PATH=$PATH:/new/directory
Description: Sets the value of an environment variable.
8. unset (Unset):
Syntax: unset [variable]
Example: unset MY_VAR
Description: Removes the value of an environment variable.
9. type (Type):
Syntax: type [command]
Example: type ls
Description: Displays information about the type of command.
These are just a few examples of internal commands available in Unix/Linux shells. Each of these
commands is directly built into the shell and can be executed without referencing an external
executable file.
10. help:
Description:Display help information for shell builtins.
Syntax: help [builtin_command]
Example: help cd
Page no.8
Khushi Sahu 0801CA231074
7.What are external commands. Define it? Explain any 10 commands with
syntax and examples.
External commands refer to the commands in a command-line interface (CLI) or shell that are not
built into the shell itself but are instead separate executable programs stored in the file system. These
commands perform various tasks such as managing files, manipulating text, executing programs, etc.
Here are ten commonly used external commands in Unix/Linux systems along with their syntax and
examples:
1.ls - List directory contents
Syntax: ls [options] [file/directory]
Example: ls -l /home/user/Documents
Page no.9
Khushi Sahu 0801CA231074
These are just a few examples of external commands in Unix/Linux systems. There are many more
commands available, each serving a specific purpose in managing and interacting with the system and
its resources.
8.What are the file manipulation commands explain it? Give 5 commands
with syntax and example.
File manipulation commands are used to perform various operations on files and directories within a
Unix/Linux environment. These commands allow users to create, modify, copy, move, and delete files
and directories. Here are five common file manipulation commands along with their syntax and
examples:
1. pwd (Print Working Directory):
Syntax: pwd
Example: pwd
Description: Prints the current working directory.
1. cd (Change Directory):
Syntax: cd [directory]
Example: cd Documents
Description: Changes the current working directory to the specified directory.
3.mkdir:(Making directory/folder)
Description: Creates directories.
Syntax: mkdir [options] directory_name(s)
Example:
Create a new directory: mkdir new_directory
Create nested directories: mkdir -p parent_directory/child_directory
4.rmdir(removing a directory)
Description: Removes empty directories.
Syntax: rmdir [options] directory_name(s)
Example:
Remove an empty directory: rmdir empty_directory
5.touch(creating a file)
Description: Creates empty files or updates access and modification timestamps of existing files.
Syntax: touch [options] filename(s)
Example:
Page no.10
Khushi Sahu 0801CA231074
6.cat(viewing a file)
Description: Concatenates and displays the contents of files.
Syntax: cat [options] file(s)
Example:
Display contents of a file: cat file.txt
Concatenate multiple files and display their contents: cat file1.txt file2.txt
7.rm(removing a file)
Description: Removes (deletes) files or directories.
Syntax: rm [options] file(s)/directory(s)
Example:
Remove a file: rm file.txt
Remove multiple files: rm file1.txt file2.txt
Remove a directory and its contents recursively: rm -r directory
10.ls:
Description: Lists directory contents.
Syntax: ls [options] [file/directory]
Example:
List files in the current directory: ls
List files with detailed information: ls -l
List all files, including hidden files: ls -a
These commands provide essential functionality for managing files and directories in Unix/Linux
environments.
Page no.11
Khushi Sahu 0801CA231074
LAB ASSIGNMENT 2
Program 1: Linux shell script program to create and print the values of variable.
country="India"
year=2021
echo "Country name: $country"
echo "Year: $year"
Page no.12
Khushi Sahu 0801CA231074
Program 3: Linux shell script program to swap two numbers using third variable and
without using third variable.
Using third variable:
num1=10
num2=20
echo "Before Swapping : Num1: $num1 Num2: $num2"
num3=$num1
num1=$num2
num2=$num3
echo "After Swapping: Num1: $num1 Num2: $num2"
Program 4: Linux shell script program to print program name using command line
argument and also Linus shell script program to execute ‘ls’ command.
echo "Script program Name: $0"
cd /
ls
Page no.13
Khushi Sahu 0801CA231074
Program 6: Linux shell script to display good morning, good afternoon, good evening
according to system time.
hour=$(date +%H)
if [ $hour -lt 12 ]
then
greet="Good Morning"
elif [ $hour -le 16 ]
then
greet="Good Afternoon"
elif [ $hour -lt 20 ]
then
greet="Good Evening"
else
greet="Good Night"
fi
echo "$greet"
Program 7: Linux shell script program to demonstrate the ‘$#’ variable and Linux shell
script program to print the current process id.
# Linux shell script program to print the current process id.
echo "Current process identifier: $$"
Page no.14
Khushi Sahu 0801CA231074
Program 11: Linux shell script to find greatest of two number and three number from
user input.
echo "Enter the first number:"
read num1
echo "Enter the second number:"
read num2
echo "Enter the third number (optional, press Enter if not applicable):"
read num3
# Checking for greatest number among two
if [ "$num3" = "" ]; then
if [ "$num1" -gt "$num2" ]; then
Page no.15
Khushi Sahu 0801CA231074
Program 12: Linux shell script factorial of number from user input.
echo "Enter a number:"
read number
factorial=1
# Check if the number is less than 0
if [ $number -lt 0 ]; then
echo "Factorial is not defined for negative numbers."
exit
fi
# Calculate factorial
for (( i=1; i<=$number; i++ )); do
factorial=$((factorial * i))
done
echo "The factorial of $number is: $factorial"
Page no.16
Khushi Sahu 0801CA231074
Program 14: Linux shell script program whether year is leaping year or not?
echo "Enter a year:"
read year
# Check if the year is divisible by 4 and not divisible by 100
if [ $((year % 4)) -eq 0 ] && [ $((year % 100)) -ne 0 ]; then
echo "$year is a leap year."
# Check if the year is divisible by 400
elif [ $((year % 400)) -eq 0 ]; then
echo "$year is a leap year."
else
echo "$year is not a leap year."
fi
Page no.17
Khushi Sahu 0801CA231074
LAB ASSIGNMENT 3
PROGRAM 1:Write a shell script to generate marksheet of a student. Take 3 subjects, calculate
and display total marks, percentage and Class obtained by the student. Take marks from the user
terminal.
# Taking input from the user
echo "Enter marks for Subject 1:"
read subject1
echo "Enter marks for Subject 2:"
read subject2
echo "Enter marks for Subject 3:"
read subject3
# Calculating percentage
percentage=$(echo "scale=2; ($total_marks / 300) * 100" | bc)
# Displaying marksheet
echo "-----------------------"
echo " MARKSHEET "
echo "-----------------------"
echo "Subject 1: $subject1"
echo "Subject 2: $subject2"
echo "Subject 3: $subject3"
echo "-----------------------"
echo "Total Marks: $total_marks"
echo "Percentage: $percentage%"
echo "Class Obtained: $class_obtained"
PROGRAM 2: Write a shell script to find the largest among the 3 given numbers in UNIX / Linux.
Using looping statements.
# Taking input from the user
echo "Enter three numbers:"
read num1
read num2
Page no.18
Khushi Sahu 0801CA231074
read num3
PROGRAM 3: Write a menu driven shell script which will print the following menu and execute
the given task.
a) Display calendar of current month
b) Display today’s date and time
c) Display usernames those are currently logged in the
system
d) Display your name at given x, y position
e) Display your terminal number
f) Exit
while true; do
# Displaying the menu
echo "MENU:"
echo "a) Display calendar of current month"
echo "b) Display today’s date and time"
echo "c) Display usernames those are currently logged in the system"
echo "d) Display your name at given x, y position"
echo "e) Display your terminal number"
echo "f) Exit"
echo -n "Enter your choice: "
read choice
case $choice in
a)
# Display calendar of current month
cal
;;
b)
# Display today's date and time
date
;;
c)
# Display usernames currently logged in
who
;;
d)
# Display name at given x, y position
echo -n "Enter X position: "
read x
echo -n "Enter Y position: "
read y
Page no.19
Khushi Sahu 0801CA231074
tput cup $x $y
echo "Your Name"
;;
e)
# Display terminal number
tty
;;
f)
# Exit the program
echo "Exiting..."
exit 0
;;
*)
echo "Invalid option, please choose again."
;;
esac
done
Page no.20
Khushi Sahu 0801CA231074
PROGRAM 4: Write a shell script that displays a list of all the files in the current directory.
# Displaying list of files in current directory
echo "List of files in the current directory:"
ls
PROGRAM 5: Write a shell script that receives any number of file names as arguments checks if
every argument supplied is a file or a directory and reports accordingly. whenever the argument is
a file or directory.
# Loop through each argument
for arg in "$@"; do
# Check if the argument is a file
if [ -f "$arg" ]; then
echo "$arg is a file."
# Check if the argument is a directory
elif [ -d "$arg" ]; then
echo "$arg is a directory."
# If the argument is neither a file nor a directory
else
echo "$arg is not a valid file or directory."
fi
done
PROGRAM 7: Write a Shell script to list all of the directory files in a directory
# Check if directory argument is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <directory>"
exit 1
Page no.21
Khushi Sahu 0801CA231074
fi
PROGRAM 9: Write Shell Script to calculate power of a number using while & for loop
#!/bin/bash
Page no.22
Khushi Sahu 0801CA231074
fi
# Calculating HCF
while [ $num2 -ne 0 ]; do
remainder=$((num1 % num2))
num1=$num2
num2=$remainder
done
echo "HCF of $num1 and $num2 is: $num1"
Page no.23
Khushi Sahu 0801CA231074
make_directory "$directory_name"
PROGRAM 12: Write Shell Script Counting characters, words & lines in the file.
#!/bin/bash
PROGRAM 14: Write Shell Script for simple calculator to perform addition subtraction
multiplication and division based on the symbol using case statements.
#!/bin/bash
Page no.24
Khushi Sahu 0801CA231074
PROGRAM 15: Write Shell Script for Add array elements - Shell Script
# Define an array
my_array=(10 20 30 40 50)
Page no.25
Khushi Sahu 0801CA231074
PROGRAM 17: Write shell script program to addition, subtraction, multiplication of two matrix.
#!/bin/bash
Page no.26
Khushi Sahu 0801CA231074
display_matrix result
}
Page no.27
Khushi Sahu 0801CA231074
PROGRAM 18: Write Shell program to add two numbers using functions.
#!/bin/bash
PROGRAM 19: Write Shell Script to compare two strings in unix shell script.
# Taking input from the user
echo -n "Enter first string: "
read string1
echo -n "Enter second string: "
read string2
PROGRAM 20: Write a shell program to demonstrate Equal operator (=), Not Equal operator (!
=),Less than (\<),Greater than (\>) operation on two strings.
# Taking input from the user
echo -n "Enter first string: "
Page no.28
Khushi Sahu 0801CA231074
read string1
echo -n "Enter second string: "
read string2
PROGRAM 21: Write a Program for system calls of Unix operating systems (opendir, readdir,
closedir).
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main() {
DIR *directory;
struct dirent *entry;
// Open directory
directory = opendir(".");
if (directory == NULL) {
perror("Unable to open directory");
exit(EXIT_FAILURE);
}
Page no.29
Khushi Sahu 0801CA231074
// Close directory
closedir(directory);
return 0;
}
PROGRAM 22: Write a Program for Process system calls of Unix operating systems (fork, getpid,
exit).
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
pid_t pid;
if (pid < 0) {
// Fork failed
perror("Fork failed");
return 1;
} else if (pid == 0) {
// Child process
printf("Child process:\n");
printf("PID: %d\n", getpid());
printf("Parent PID: %d\n", getppid());
// Child exits
exit(0);
} else {
// Parent process
printf("Parent process:\n");
printf("PID: %d\n", getpid());
printf("Child PID: %d\n", pid);
// Wait for child to finish
wait(NULL);
}
return 0;
}
Page no.30
Khushi Sahu 0801CA231074
PROGRAM 23: Write the program to implement the system calls wait ( ) and exit ( ).
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
int status;
if (pid < 0) {
// Fork failed
perror("Fork failed");
return 1;
} else if (pid == 0) {
// Child process
printf("Child process is running...\n");
// Simulating some task in the child process
sleep(3);
printf("Child process is done.\n");
// Child exits
exit(42);
} else {
// Parent process
printf("Parent process is waiting for child...\n");
// Wait for child to finish and collect its exit status
wait(&status);
if (WIFEXITED(status)) {
printf("Child process exited with status: %d\n", WEXITSTATUS(status));
}
printf("Parent process is done.\n");
}
return 0;
}
int main() {
printf("Parent process executing...\n");
Page no.31
Khushi Sahu 0801CA231074
if (pid < 0) {
// Fork failed
perror("Fork failed");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
printf("Child process executing...\n");
return 0;
}
int main() {
printf("Parent process executing...\n");
if (pid < 0) {
// Fork failed
perror("Fork failed");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
printf("Child process executing...\n");
Page no.32
Khushi Sahu 0801CA231074
}
} else {
// Parent process
printf("Parent process waiting for the child...\n");
wait(NULL);
printf("Parent process done.\n");
}
return 0;
}
int main() {
int input_fd, output_fd; // File descriptors for input and output files
ssize_t bytes_read, bytes_written;
char buffer[BUFFER_SIZE];
// Read from the input file and write to the output file
while ((bytes_read = read(input_fd, buffer, BUFFER_SIZE)) > 0) {
bytes_written = write(output_fd, buffer, bytes_read);
if (bytes_written != bytes_read) {
perror("Write error");
close(input_fd);
close(output_fd);
exit(EXIT_FAILURE);
}
Page no.33
Khushi Sahu 0801CA231074
if (bytes_read == -1) {
perror("Read error");
close(input_fd);
close(output_fd);
exit(EXIT_FAILURE);
}
return 0;
}
Page no.34
Khushi Sahu 0801CA231074
LAB ASSIGNMENT 4
PROGRAM 1:Write the C program to implement CPU & scheduling algorithm for first come first serve
scheduling Take user input.
#include <stdio.h>
#define MAX_PROCESS 10
current_time = completion_time[i];
}
printf("\n\n");
printf("P_id |\tAT|\t BT|\t CT|\tTAT|\t WT|\n");
printf("----------------------------------------\n");
for (int i = 0; i < n; i++) {
int waiting_time = completion_time[i] - arrival_time[i] - burst_time[i];
printf("\t%d| \t %d| \t%d| \t %d | \t%d | \t%d | \n", i + 1, arrival_time[i], burst_time[i], completion_time[i],
completion_time[i] - arrival_time[i], waiting_time);
}
int main()
{
int arrival_time[MAX_PROCESS], burst_time[MAX_PROCESS];
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
printf("Enter arrival time and burst time for each process:\n");
for (int i = 0; i < n; i++)
{
printf("Process %d: ", i + 1);
scanf("%d %d", &arrival_time[i], &burst_time[i]);
}
fcfs(arrival_time, burst_time, n);
return 0;
}
Page no.35
Khushi Sahu 0801CA231074
PROGRAM 2:Write a program to implement CPU scheduling algorithm for shortest job first Scheduling.
Take user input.
#include <stdio.h>
#define MAX_PROCESS 10
int current_time = 0;
int completed_processes = 0;
if (shortest_job == -1) {
current_time++;
continue;
}
// If a process is completed
if (remaining_time[shortest_job] == 0) {
completion_time[shortest_job] = current_time;
completed_processes++;
total_waiting_time += completion_time[shortest_job] - arrival_time[shortest_job] -
burst_time[shortest_job];
Page no.36
Khushi Sahu 0801CA231074
printf("P_id\tAT\tBT\tCT\tTAT\tWT\n");
for (int i = 0; i < n; i++) {
printf("\t%d\t%d\t%d\t%d\t%d\t%d\n", i + 1, arrival_time[i], burst_time[i], completion_time[i],
completion_time[i] - arrival_time[i], completion_time[i] - arrival_time[i] - burst_time[i]);
}
int main() {
int arrival_time[MAX_PROCESS], burst_time[MAX_PROCESS];
int n;
return 0;
}
PROGRAM 3: Write a program to implement CPU scheduling algorithm for Shortest Job Remaining First.
Take user input.
PROGRAM 4:write a ‘C’ program to perform priority scheduling and take user input.
PROGRAM 5: write a program to implement CPU scheduling for Round Robin Scheduling.
Page no.37