Professional Documents
Culture Documents
return #;
// end of ch%process
int ne(tprocess&' // function to identifF the ne(t process to be e(ecuted
{
S8B=, =CMDC7
Page 12
SS & OS Lab Manual
int min) l) i;
min 7 30###; //anF limit assumed
for&i 7 "; i <7 no; i88'
{
if& process!i$.remE7# 55 process!i$.rem < min'
{
min 7 process!i$.rem;
l 7 i;
return l;
// end of ne(tprocess
void srtf&int n'
{
int i)+)%)time7#;
float tavg)wavg;
for&i 7 "; i <7 n; i88'
{
process!i$.id 7 i;
printf&,.n.n-nter the arrival time for process 4d6 ,) i';
scanf&,4d,) 5&process!i$.arrival'';
printf&,-nter the burst time for process 4d6 ,) i';
scanf&,4d,) 5&process!i$.burst'';
process!i$.rem 7 process!i$.burst;
for&i 7 "; i <7 n; i88'
{
for&+ 7 i 8 "; + <7 n; +88'
{
if&process!i$.arrival > process!+$.arrival' // sort arrival time of a process
{
temp 7 process!i$;
process!i$ 7 process!+$;
process!+$ 7 temp;
no 7 #;
+ 7 ";
while&ch%process&n' 77 "'
{
if&process!no 8 "$.arrival 77 time'
{
no88;
S8B=, =CMDC7
Page 1O
SS & OS Lab Manual
if&process!+$.rem77#'
process!+$.finish7time;
+ 7 ne(tprocess&';
else
{
process!+$.finish 7 time;
+7ne(tprocess&';
time99;
%7+;
time88;
process!%$.finish 7 time;
printf&,.n.n.t.t.t9991:;/2-12 /-<=>?>?@ 2><- G>/12999,';
printf&,.n.n Process =rrival Curst Daiting Ginishing turnaround 2r/2b .n,';
printf&,4Hs 4Is 4Js 4"#s 4Ks 4Is.n.n,) ,id,) ,time,) ,time,) ,time,) ,time,) ,time,';
for&i 7 "; i <7 n; i88'
{
process!i$.turnaround 7 process!i$.wait 8 process!i$.burst; // calc of turnaround
process!i$.ratio 7 &float'process!i$.turnaround / &float'process!i$.burst;
printf&,4Hd 4Kd 4Jd 4Kd 4"#d 4Id 4"#."f ,) process!i$.id) process!i$.arrival)
process!i$.burst) process!i$.wait) process!i$.finish) process!i$.turnaround)
process!i$.ratio';
tavg7tavg8 process!i$.turnaround; //summation of turnaround time
wavg7wavg8process!i$.wait; // summation of waiting time
printf&,.n.n,';
p!+$.ma(!%$7#;
p!+$.all!%$7#;
p!+$.need!%$7#;
p!+$.finished7#;
p!+$.re*uest!%$7#;
for&i7#;i<n;i88'
{
printf&,.n.n.t -nter <a( and =llocated resources for P 4d 6 ,)i';
for&+7#;+<nor;+88'
{
printf&,.n.n.t -nter the <a( of resource 4d 6 ,)+';
scanf&,4d,)5p!i$.ma(!+$';
printf&,.n.n.t =llocation of resource 4d 6,)+';
scanf&,4d,)5p!i$.all!+$';
if&p!i$.all!+$>p!i$.ma(!+$'
S8B=, =CMDC7
Page *+
SS & OS Lab Manual
{
printf&,.n.n.t =llocation should be less < or 77
ma(,';
+99;
else
p!i$.need!+$7p!i$.ma(!+$9p!i$.all!+$;
avail!+$7avail!+$9p!i$.all!+$;
brea%;
case 06
violationchec%7#;
waitchec%7#;
printf&,.n.n.t /e*uesting process id 6,';
scanf&,4d,)5pid';
for&+7#;+<nor;+88'
{
printf&,.n.n.t ?umber of /e*uest for resource 4d 6,)+';
scanf&,4d,)5p!pid$.re*uest!+$';
if&p!pid$.re*uest!+$>p!pid$.need!+$'
violationchec%7";
if&p!pid$.re*uest!+$>avail!+$'
waitchec%7";
if &violationchec%77"'
printf&,.n.n.t 2he Process -(ceeds itOs <a( ?eed6 2erminated,';
else if&waitchec%77"'
printf&,.n.n.t Pac% of /esourcess 6 Process 1tate Q Dait,';
else
{
for&+7#;+<nor;+88'
{
avail!+$7avail!+$9p!pid$.re*uest!+$;
p!pid$.all!+$7p!pid$.all!+$8p!pid$.re*uest!+$;
p!pid$.need!+$7p!pid$.need!+$9p!pid$.re*uest!+$;
ch"7safese*&';
if&ch"77#'
{
for&+7#;+<nor;+88'
{
avail!+$7avail!+$8p!pid$.re*uest!+$;
p!pid$.all!+$7p!pid$.all!+$9p!pid$.re*uest!+$;
p!pid$.need!+$7p!pid$.need!+$8p!pid$.re*uest!+$;
else if&ch"77"'
printf&,.n.n.t /e*uest Rommitted ,';
brea%;
case 36
if&safese*&'77"'
S8B=, =CMDC7
Page *X
SS & OS Lab Manual
printf&,.n.n.t 2he 1Fstem is in safe state ,';
else
printf&,.n.n.t 2he 1Fstem is ?ot in safe state ,';
brea%;
case M6
printf&,.n.n.t ?umber of processes 6 4d,)n';
printf&,.n.n.t ?umber of /esources 6 4d,)nor';
printf&,.n.n.t Pid .t <a( .t =llocated .t ?eed ,';
for&i7#;i<n;i88'
{
printf&,.n.n.t P4d 6 ,)i';
for&+7#;+<nor;+88'
printf&, 4d,)p!i$.ma(!+$';
printf&,.t,';
for&+7#;+<nor;+88'
printf&,4d,)p!i$.all!+$';
printf&,.t,';
for&+7#;+<nor;+88'
printf&,4d,)p!i$.need!+$';
//getch&';
while&chE7H';
int safese*&'
{
int t+)t%)i)+)%;
ss7#;
for&+7#;+<nor;+88'
wor%!+$7avail!+$;
for&+7#;+<n;+88'
p!+$.finished7#;
for& t%7#;t%<nor;t%88'
{
for&+7#;+<n;+88'
{
if&p!+$.finished77#'
{
chec%"7#;
for&%7#;%<nor;%88'
if&p!+$.need!%$<7wor%!%$'
chec%"88;
if&chec%"77nor'
{
for&%7#;%<nor;%88'
{
S8B=, =CMDC7
Page *Z
SS & OS Lab Manual
wor%!%$7wor%!%$8p!+$.all!%$;
p!+$.finished7";
sse*!ss$7+;
ss88;
chec%07#;
for&i7#;i<n;i88'
if&p!i$.finished77"'
chec%088;
printf&,.n.n.t,';
if&chec%0>7n'
{
printf&,.n.n.t 2he sFstem is in safe state,';
for& t+7#;t+<n;t+88'
printf&,P4d),)sse*!t+$';
return ";
else
printf&,.n.n.t 2he sFstem is ?ot in safe state,';
return #;
S ./os"0
". >nput
0. ?ew /e*uest
3. 1afe 1tate or ?ot
M. print
H. -(it
-nter ur choice 6"
-nter number of processes 6 H
-nter the ?umber of /esources 6 3
-nter the =vailable /esouces 6
Gor /esource tFpe # 6 "#
Gor /esource tFpe " 6 H
Gor /esource tFpe 0 6 J
-nter <a( and =llocated resources for P # 6
-nter the <a( of resource # 6 J
=llocation of resource # 6#
-nter the <a( of resource " 6 H
=llocation of resource " 6"
-nter the <a( of resource 0 6 3
S8B=, =CMDC7
Page *2
SS & OS Lab Manual
=llocation of resource 0 6#
-nter <a( and =llocated resources for P " 6
-nter the <a( of resource # 6 3
=llocation of resource # 60
-nter the <a( of resource " 6 0
=llocation of resource " 6#
-nter the <a( of resource 0 6 0
=llocation of resource 0 6#
-nter <a( and =llocated resources for P 0 6
-nter the <a( of resource # 6 I
=llocation of resource # 63
-nter the <a( of resource " 6 #
=llocation of resource " 6#
-nter the <a( of resource 0 6 0
=llocation of resource 0 60
-nter <a( and =llocated resources for P 3 6
-nter the <a( of resource # 6 0
=llocation of resource # 60
-nter the <a( of resource " 6 0
=llocation of resource " 6"
-nter the <a( of resource 0 6 0
=llocation of resource 0 6"
-nter <a( and =llocated resources for P M 6
-nter the <a( of resource # 6 M
=llocation of resource # 6#
-nter the <a( of resource " 6 3
S8B=, =CMDC7
Page *O
SS & OS Lab Manual
=llocation of resource " 6#
-nter the <a( of resource 0 6 3
=llocation of resource 0 60
". >nput
0. ?ew /e*uest
3. 1afe 1tate or ?ot
M. print
H. -(it
-nter ur choice 63
2he sFstem is in safe stateP")P3)PM)P#)P0)
2he 1Fstem is in safe state
". >nput
0. ?ew /e*uest
3. 1afe 1tate or ?ot
M. print
H. -(it
-nter ur choice 60
/e*uesting process id 6"
?umber of /e*uest for resource # 6"
?umber of /e*uest for resource " 6#
?umber of /e*uest for resource 0 60
2he sFstem is in safe stateP")P3)PM)P#)P0)
/e*uest Rommitted
". >nput
0. ?ew /e*uest
3. 1afe 1tate or ?ot
M. print
H. -(it
-nter ur choice 60
S8B=, =CMDC7
Page I'
SS & OS Lab Manual
/e*uesting process id 60
?umber of /e*uest for resource # 60
?umber of /e*uest for resource " 60
?umber of /e*uest for resource 0 63
2he Process -(ceeds ites <a( ?eed6 2erminated
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL B:>
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
S8B=, =CMDC7
Page I1