0% found this document useful (0 votes)
32 views

OS Lab Manual.docx_removed

The document outlines the Operating System Lab course for the Computer Engineering department at Datta Meghe College of Engineering, detailing various experiments and assignments related to Linux commands, shell scripting, and system calls. It includes course outcomes, program educational objectives, and rubrics for grading experiments and assignments. The document emphasizes the importance of practical knowledge and skills in computer engineering to prepare students for future challenges in technology and research.

Uploaded by

waghjayesh07
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)
32 views

OS Lab Manual.docx_removed

The document outlines the Operating System Lab course for the Computer Engineering department at Datta Meghe College of Engineering, detailing various experiments and assignments related to Linux commands, shell scripting, and system calls. It includes course outcomes, program educational objectives, and rubrics for grading experiments and assignments. The document emphasizes the importance of practical knowledge and skills in computer engineering to prepare students for future challenges in technology and research.

Uploaded by

waghjayesh07
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/ 35

DEPARTMENT OF COMPUTER

ENGINEERING ACADEMIC YEAR : 2022 –


23 (TERM – II)

List of
Datta Meghe College of Experiments Course Name : Operating
Engineering
System Course Code :
Airoli, Navi Mumbai CSL403/CSC404

Sr. Name of experiment Cos Page Date of Date of Marks &


No Covered No. Performance Submission Signature
1 To study and implement the CSC404.1
internal commands of Linux &
like ls, chdir, mkdir,chown , CSC404.5
chmod , chgrp, ps , etc

2 To study and implement the CSC404.1


shell scripts.

3 To study and implement the CSC404.1


following system calls:
open, read, write, close,
getpid, setpid, getuid,
getgid, getegid, geteuid.

4 To Implement basic CSC404.1


commands of Linux like
ls, cp, mv and others using
kernel APIs.

5 To implement CPU CSC404.3


Scheduling algorithms like
FCFS & SJF
6 Program to simulate CSC404.3
producer and consumer
problem using semaphores

7 Write​ a​ program​ to CSC404.3


demonstrate the concept of
deadlock avoidance through
Banker’s Algorithm
8 Write​ a​ program​ to CSC404.4
implement​ ​ dynamic
partitioning​
placement algorithms i.e
Best Fit, First
–Fit and Worst –Fit.
9 Write a program to CSC404.4
implement various
page replacement
policies.
10 Write a program to CSC404.6
implement Disk Scheduling
algorithms like FCFS,
SCAN and C-SCAN.

11 To Write a C program to CSC404.4


simulate the concept of
Dining-Philosophers
problem.

12 To write a C program for CSC404.5


implementing sequential
file allocation method

Assignment 1 and 2 All

This is to certify that Mr. / Miss​ of

​ Roll No.​ has performed the Experiments / Assignments / Tutorials

/ Case Study Work mentioned above in the premises of the institution.

Practical Incharge
DATTA MEGHE COLLEGE OF ENGINEERING, AIROLI, NAVI
MUMBAI

DEPARTMENT OF COMPUTER ENGINEERING

Institute Vision​ :​ To create value - based technocrats to fit in the world of work and research

Institute Mission​ :​ To adapt the best practices for creating competent human beings to
work in the world of technology and research.

Department Vision​ :​ To provide an intellectually stimulating environment for education,


technological excellence in computer engineering field and professional
training along with human values.

Department Mission :
M1:​ To promote an educational environment that combines academics with intellectual curiosity.

M2:​ To develop human resource with sound knowledge of theory and practical in the discipline of

Computer Engineering and the ability to apply the knowledge to the benefit of society at large.

M3:​ To assimilate creative research and new technologies in order to facilitate students to be a lifelong
learner who will contribute positively to the economic well-being of the nation.

Program Educational Objectives (PEO)


PEO1: To explicate optimal solutions through application of innovative computer science techniques
that aid towards betterment of society.
PEO2:​ To adapt recent emerging technologies for enhancing their career opportunity prospects.
PEO3: To effectively communicate and collaborate as a member or leader in a team to manage
multidisciplinary projects.
PEO4:​ To prepare graduates to involve in research, higher studies or to become entrepreneurs
in long run.

Program Specific Outcomes (PSO)


PSO1: To apply basic and advanced computational and logical skills to provide solutions to
computer engineering problems.
PSO2: Ability to apply standard practices and strategies in design and development of software
and hardware based systems and adapt to evolutionary changes in computing to meet
the challenges of the future.
PSO3: To develop an approach for lifelong learning and utilize multi-disciplinary knowledge
required for satisfying industry or global requirements.
Program Outcomes as defined by NBA

(PO)Engineering Graduates will be able to:

1.​ Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.
2.​ Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
3.​ Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
4.​ Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5.​ Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modelling to complex engineering activities with an
understanding of the limitations.
6.​ The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
7.​ Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
8.​ Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9.​ Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10.​ Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations, and give and receive clear instructions.
11.​ Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader in a
team, to manage projects and in multidisciplinary environments.
12.​ Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
Datta Meghe College of Engineering, AiroliDepartment of Computer Engineering
Course Name: Operating System Lab
(R-19) Course Code: CSC403

Year of Study: S.E., Semester: IV

Course Outcomes
CSC404.1 Understand the objectives, functions and structure of OS

Analyze the concept of process management and evaluate performance of


CSC404.2
process scheduling algorithms.

CSC404.3 Understand and apply the concepts of synchronization and deadlocks

CSC404.4 Evaluate performance of Memory allocation and replacement policies

CSC404.5 Understand the concepts of file management.

CSC404.6 Apply concepts of I/O management and analyze techniques of disk scheduling.
DATTA MEGHE COLLEGE OF ENGINEERING
DEPARTMENT OF COMPUTER
ENGINEERING ACADEMIC YEAR 2022-23
(TERM II) SUBJECT: OERATING SYSTEM
SEM: IV
RUBRICS FOR GRADING EXPERIMENTS
Rubric Rubric Title Criteria Marks
Number
(out of 15)

R1 Punctuality, On-time 3
Completion Time
Delayed by not more than a Week 2
/ Timeline
Delayed more than a Week 1

R2 Knowledge & Clear understanding 3


Concept
Partially understood 2

Weak understanding 1

R3 Implementation Correct Implementation 3

Partial Implementation 2

Implementation with error 1

R4 Results Correct Results 3

Partial Results 2

Results with error 1

R5 Documentation Correct Documentation 3

Moderate documented 2

Not properly organized 1


DATTA MEGHE COLLEGE OF

ENGINEERING DEPARTMENT OF

COMPUTER ENGINEERING ACADEMIC

YEAR 2022-23 (TERM II) SUBJECT:

OPERATING SYSTEM

SEM: IV

RUBRICS FOR GRADING


ASSIGNMENTS

Rubric Rubric Title Criteria Marks


Number
(out of 5)

R1 Punctuality, On-time 2
Completion Time
Delayed by not more than a Week 1
/ Timeline
Delayed more than a Week 0

R2 Knowledge & Clear understanding 2


Concept
Partially understood 1

Weak understanding 0

R3 Documentation Correct Documentation 1

Not documented properly 0


EXPERIMENT NO:-1

AIM:-To study and implement the internal commands of Linux like ls, chdir, mkdir,
chown , chmod , chgrp, ps , etc

THEORY:-
WHAT IS LINUX?
Linux is an Operating System’s Kernel. You might have heard of UNIX. Well, Linux is a
UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free
and open-source, that means that you can simply change anything in Linux and
redistribute it in your own name! There are several Linux Distributions, commonly called
“distros”. A few of them are:
●​ Ubuntu Linux
●​ Red Hat Enterprise Linux
●​ Linux Mint
●​ Debian
●​ Fedora

1.​ Command - ls

Name list command


Purpose functions in the Linux terminal to show all of the major directories filed
under a given file system, will also show the user all of the folders stored
in the specified folder.
Options:
a- used to list all the files including the hidden files.
c - list all the files columnwise.
d - list all the directories.
m - list the files separated by commas.
p - list files include „/‟ to all the
directories. r - list the files in reverse
alphabetical order.
f - list the files based on the list modification
date. x - list in column wise sorted order.
Syntax $ ls – options <arguments>
Example ls /

OUTPUT:
2.​ Command – chmod

Name change mode command


Purpose Permissions can be changed by owner of the file
Symbolic modes-
User(u) - the owner of the file
Group(g) - users who are members of the file’s group
Others(o) - users who are not the owner of the file or members of a
group All(a) - three of the above; is the same as ugo
Read(r) - read a file or list a directory’s
contents Write(w) - write to a file or directory
Execute( x) - execute a file or recurse a directory tree

Syntax $ chmod ug+x file


Example $ chmod 400 test.php

OUTPUT:

3.​ Command - Sort

Name sort command


Purpose sort command can be used to get sorted content
Syntax $ sort file
Example Let's say you have a file, data.txt, which contains the following ASCII
text: apples
oranges
pears
kiwis
bananas
To sort the lines in this file alphabetically, use the following command:
$ sort data.txt
OUTPUT:

4.​Command - chdir

Name chdir command- change directory


Purpose chdir is the system function for changing the current working directory.
Syntax $ chdir name of the directory

Example chdir /

OUTPUT:

5.​Command - mkdir

Name mkdir command –make directory


Purpose Create the DIRECTORY(ies), if they do not already exist.
Syntax $ mkdir directory_name
Example $ mkdir images
$ls

OUTPUT:
6.​Command - chown

Name chown

Purpose To change owner, change the user and/or group ownership of each given
File to a new Owner.
Syntax chown [options] new_owner object(s)

Example The following would transfer the ownership of a file named file1 and a
directory named dir1 to a new owner named alice:
chown root test.php
OUTPUT:

7.​Command - chgrp

Name chgrp
Purpose 'chgrp' command changes the group ownership of each given File to
Group (which can be either a group name or a numeric group id) or to
match the same group as an existing reference file.
Syntax chgrp [OPTION]… GROUP FILE…
Example To Make oracleadmin the owner of the database directory
$ chgrp wheel .

OUTPUT:
8.​Command - ps

Name ps
Purpose displays information about a selection of the active processes.
Syntax ps aux
Example $ ps aux

OUTPUT:

9.​Command – man

Name man
Purpose It is used to show the manual of the inputted command.
Syntax $ man <command_name>
Example The inputting command will show the manual or all relevant information
for the change directory command.
$ man cd

OUTPUT:
10.​Command – rm

Name rm - remove file


Purpose It is used to remove files from your Linux OS.
Syntax rm filename.txt
Example $ rm tmp.txt

OUTPUT:

CONCLUSION:- Hence we have studied and implemented internal commands of


Linux successfully.

SIGN AND REMARK

R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)


EXPERIMENT NO:-2

AIM: - To study and implement the shell scripts.

THEORY: -
SHELL SCRIPTS:
Shell scripts are short programs that are written in a shell programming
language and interpreted by a shell process. They are extremely useful for automating
tasks on Linux and other Unix-like operating systems.
A shell is a program that provides the traditional, text-only user interface for
Unix- like operating systems. Its primary function is to read commands (i.e., instructions)
that are typed into a console (i.e., an all-text display mode) or terminal window (i.e.,
all-text mode window) and then execute (i.e., run) them. The default shell on Linux is the
very commonly used and highly versatile bash.

Steps to write and execute a script:


•​ Open the terminal. Go to the directory where you want to create your script.
•​ Create a file with .sh extension.
•​ Write the script in the file using an editor.
•​ Make the script executable with command chmod +x <fileName.sh>.
•​ Run the script using ./<fileName.sh>.
Example: Print HELLO WORLD using shell
script. #!/bin/bash
echo “HELLO WORLD”

SHELL SCRIPTS EXAMPLE:


1.​ Display top 10 processes in descending order
The following command will show the list of top processes ordered by RAM and CPU
use in descendant form (remove the pipeline and head if you want to see the full list)

# ps –eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head

The process list shows all the processes with various process specific details in separate
columns.Some of the column names are pretty self explanatory.
PID –Process ID
USER - The system user account running the process.
%CPU - CPU usage by the process.
%MEM - Memory usage by the process
COMMAND - The command (executable file) of the process
OUTPUT:

2.​ Display processes with highest memory usage.


To find the process consuming the most CPU or memory, simply sort the list.
Press M key (yes, in capital, not small) to sort the process list by memory usage.
Processes using the most memory are shown first and rest in order.
Here are other options to sort by CPU usage, Process ID and Running Time
- Press 'P' – to sort the process list by cpu usage.
Press 'N' - to sort the list by process
id Press 'T' - to sort by the running
time.

OUTPUT:

3.​ Display current logged in user and logname

echo "Hi, $USER! Let us be


friends." echo "Hello, $LOGNAME!
"
OUTPUT:

4.​ Display OS Version , release number , kernel version


$ uname -a (Print all Information)
$ uname -r (Print the kernel name)
$ cat /proc/version
$ cat /etc/issue
$ cat /etc/redhat-release

OUTPUT:

CONCLUSION:- Thus we have studied and implemented shell script programs


successfully.

SIGN AND REMARK

R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)


EXPERIMENT NO:-3

AIM:- To study and implement the following system calls: open, read, write, close,
getpid, setpid, getuid, getgid, getegid, geteuid.

THEORY: -
SYSTEM CALL:
When a program in user mode requires access to RAM or a hardware resource, it
must ask the kernel to provide access to that resource. This is done via something called a
system call.
When a program makes a system call, the mode is switched from user mode to kernel
mode. This is called a context switch.
Then the kernel provides the resource which the program requested. After that, another
context switch happens which results in change of mode from kernel mode back to user
mode.
Generally, system calls are made by the user level programs in the following situations:

●​ Creating, opening, closing and deleting files in the file system.


●​ Creating and managing new processes.
●​ Creating a connection in the network, sending and receiving packets.
●​ Requesting access to a hardware device, like a mouse or a printer.

In a typical UNIX system, there are around 300 system calls.


1.​ Opening a File: open()
Description: “open()” allows you to open or create a file for reading and/or writing.
Syntax: int open( char* fileName, int mode[, int permissions])
Where
fileName : an absolute or relative pathname,
mode : a bitwise or’ing of a read/write flag together with zero or more miscellaneous
flags. permission : a number that encodes the value of the file’s permission flags.
OUTPUT:
2.​ Reading From a File : read()
Description: To read bytes from a file, it uses the “read()” system call.

Syntax: ssize_t read( int fd, void* buf, size_t count)


Here “read()” copies count bytes from the file referenced by the file descriptor fd into the
buffer buf.

OUTPUT:
3.​ Writing to a File: write()
Description: To write bytes to a file, it uses the “write()” system call,

Syntax: ssize_t write( int fd, void* buf, size_t count)


Here “write()” copies count bytes from a buffer buf to the file referenced by the file descriptor
fd.

OUTPUT:
4.​ Closing a File: “close()”
Description: uses the “close()” system call to free the file descriptor of the input.

Syntax: int close(int fd)

Here “close()” frees the file descriptor fd.


✔ If fd is the last file descriptor associated with a particular open file, the kernel resources
associated with the file are deallocated.
✔ If successful, “close()” returns a value of 0;otherwise, it returns a value of -1.

OUTPUT:
5.​ Process management - getpid() & getppid()
Description: A process may obtain its own process ID and parent process ID
numbers by using the “getpid()” and “getppid()” system calls, respectively.

Syntax: pid_t getpid(void)


pid_t getppid(void)

Here “getpid()” and “getppid()” return a process’ID number and parent process’ ID
number, respectively.
The parent process ID number of PID 1 (i.e., “init”) is 1.

OUTPUT:
6.​ Accessing User and Group IDs
Description: The system calls that allow you to read a process real and effective IDs

Syntax: uid_t getuid()


uid_t geteuid()
gid_t getgid()
gid_t getegid()
Here,
“getuid()” and “geteuid()” return the calling process’ real and
effective user IDs, respectively.
“getgid()” and “getegid()” return the calling process’ real and
effective group IDs, respectively.
The ID numbers correspond to the user and group IDs listed
in “/etc/passwd” and “/etc/group” files.
These calls always succeed.

OUTPUT:
CONCLUSION:- Thus we have studied and explored the commands of system calls.

SIGN AND REMARK

R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)


EXPERIMENT NO:-4

AIM: - To Implement basic commands of Linux like ls, cp, mv and others using kernel
APIs.

THEORY:-
1.​ Command – stat

Name stat
Purpose To check the status of a file. This provides more detailed information
about a file than ‘ls -l’ output.
Syntax $ stat usrcopy
Example stat data.txt

OUTPUT:

2.​ Command – cal


Name cal
Purpose Displays the calendar of the current month.
Syntax $ cal
Example $ cal
July 2012
Su Mo Tu We Th Fr Sa
1234567
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
OUTPUT:

3.​ Command – VI editor

Name VI editor
Purpose VI stands for Visual editor; another text editor in Linux. This is a
standard editor in many Linux/Unix environments.
Syntax $ vi filename
Example $ vi hello.txt

OUTPUT:
4.​ Command – mv

Name mv - move
Purpose Move files or directories. The 'mv' command works like 'cp' command,
except that the original file is removed. But, the mv command can be
used to rename the files (or directories).
Syntax $ mv source destination
Example mv myfile.txt myfiles
Move the file myfile.txt into the directory myfiles. If myfiles is a file, it will
be overwritten. If the file is marked as read-only, but you own the file, you
will be prompted before overwriting it.
OUTPUT:

5.​ Command copy


Name cp - copy
Purpose Copy files and directories. If the source is a file, and the destination (file)
name does not exit, then source is copied with new name i.e. with the
name provided as the destination.
Syntax $ cp source destination
Example $ cp usrlisting listing_copy.txt

OUTPUT:
6.​ Command – date
Name date
Purpose Displays current time and date.
If you are interested only in time, you can use 'date +%T' (in hh:mm:ss):
Syntax $ date
Example $ date
Fri Jul 6 01:07:09 IST 2012
$ date +%T
01:13:14

OUTPUT:

7.​ Command – whoami

Name whoami
Purpose This command reveals the user who is currently logged in.
Syntax $ whoami
Example $ whoami
raghu

OUTPUT:
8.​ Command – pwd

Name pwd
Purpose ‘pwd’ command prints the absolute path to current working directory.
Syntax $ pwd
Example $ pwd
/home/raghu

OUTPUT:

9.​ Command – touch


Name touch
Purpose For creating an empty file, use the touch command.
Syntax $ touch filename
Example $ touch file1 file2 file3
$ ls –l
total 4
drwxr-xr-x 2 raghu raghu 4096 2012-07-06 14:09 example
-rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file1
-rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file2
-rw-r--r-- 1 raghu raghu 0 2012-07-06 14:20 file3
OUTPUT:
10.​Command – wc

Name Word count


Purpose wc, or "word count," prints a count of newlines, words, and bytes for
each input file.
Syntax $ wc filename
Example wc myfile.txt
5 13 57 myfile.txt
Where 5 is the number of lines, 13 is the number of words, and 57 is the
number of characters.

OUTPUT:

CONCLUSION:- Thus we have studied and implemented basic commands of Linux


like ls, cp, mv and others using kernel APIs.

SIGN AND REMARK

R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)


EXPERIMENT NO:-5

AIM: - Write a program to implement CPU Scheduling algorithms like FCFS & SJF.

THEORY:-
1.​ FIRST-COME, FIRST-SERVE SCHEDULING (FCFS):
In this, which process enter the ready queue first is served first. The OS maintains DS
that is ready queue. It is the simplest CPU scheduling algorithm. If a process request the
CPU then it is loaded into the ready queue, which process is the head of the ready queue,
connect the CPU to that process.

Algorithm for FCFS scheduling:


Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst
time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turn around time
Step 5: for each process in the Ready Q calculate
(c)​Waiting time for process(n)=waiting time of process (n-1) + Bursttime of process(n-1)
(d)​Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
(e)​Average waiting time = Total waiting Time / Number of process
(f)​Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process

/* Program to Simulate First Come First Serve CPU Scheduling Algorithm */


#include<stdio.h>
#include<conio.h
>
#include<string.h
> void main()
{
int i,j,n,bt[10],compt[10],at[10],
wt[10],tat[10]; float​
sumwt=0.0,sumtat=0.0,avgwt,avgtat; clrscr();
printf("Enter number of processes: ");
scanf("%d",&n);
printf("Enter the burst time of %d process\n",
n); for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
printf("Enter the arrival time of %d process\n",
n); for(i=0;i<n;i++)
{
scanf("%d",&at[i]);
}
compt[0]=bt[0]-at[0];
for(i=1;i<n;i++)
compt[i]=bt[i]+compt[i-1]
; for(i=0;i<n;i++)
{
tat[i]=compt[i]-at[i];
wt[i]=tat[i]-bt[i]
; sumtat+=tat[i];
sumwt+=wt[i];
}
avgwt=sumwt/n;
avgtat=sumtat/n;
printf("​
\n"); printf("PN\tBt\tCt\tTat\tWt\n");
printf("​
\n"); for(i=0;i<n;i++)
{
printf("%d\t%2d\t%2d\t%2d\t%2d\n",i,bt[i],compt[i],tat[i],wt[i]);
}
printf("​ \n");
printf(" Avgwt = %.2f\tAvgtat =
%.2f\n",avgwt,avgtat); printf("​ \n");
getch();
}

OUTPUT:
2.​ SHORTEST JOB FIRST:
The criteria of this algorithm are which process having the smallest CPU burst, CPU is
assigned to that next process. If two process having the same CPU burst time FCFS is
used to break the tie.

Algorithm for SJF:


Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst
time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to
lowest to highest burst time.
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst
time.
Step 6: For each process in the ready queue, calculate
(a)​Waiting time for process(n)=waiting time of process (n-1) + Bursttime of process(n-1)
(b)​Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 7: Calculate
(c)​Average waiting time = Total waiting Time / Number of process
(d)​Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process

/* Program to Simulate Shortest Job First CPU Scheduling Algorithm */


#include<stdio.h>
#include<conio.h
>
#include<string.h
> void main()
{
int i,j,n,bt[10],compt[10],
wt[10],tat[10],temp; float​
sumwt=0.0,sumtat=0.0,avgwt,avgtat;
clrscr();
printf("Enter number of processes: ");
scanf("%d",&n);
printf("Enter the burst time of %d process\n",
n); for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++
) if(bt[i]>bt[j])
{
temp=bt[i]
;
bt[i]=bt[j];
bt[j]=temp
;
}
compt[0]=bt[0];
for(i=1;i<n;i++)
compt[i]=bt[i]+compt[i-1]
; for(i=0;i<n;i++)
{
tat[i]=compt[i];
wt[i]=tat[i]-bt[i]
; sumtat+=tat[i];
sumwt+=wt[i];
}
avgwt=sumwt/n;
avgtat=sumtat/n;
printf("​ \n");
printf("Bt\tCt\tTat\tWt\n");
printf("​ \n");
for(i=0;i<n;i++)
{
printf("%2d\t%2d\t%2d\t%2d\n",i,bt[i],compt[i],tat[i],wt[i]);
}
printf("​ \n");
printf(" Avgwt = %.2f\tAvgtat =
%.2f\n",avgwt,avgtat); printf("​ \n");
getch();
}
OUTPUT:

CONCLUSION:- Thus we have studied FCFS & SJF scheduling algorithm and its
implementation.
SIGN AND REMARK

R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)

You might also like