Os Lab Manual Final Os-2
Os Lab Manual Final Os-2
Os Lab Manual Final Os-2
DEPARTMENT OF CSE
Prepared By :
T. AHILANDESWARI, AP/CSE
V.GOMATHI, AP/CSE
P.SUBHAPRIYA, AP/CSE
Verified by:
Approved by:
LIST OF EXPRIMENTS
5.
6.
7.
8.
9.
10.
11.
12.
DEPARTMENT OF CSE
LIST OF EXPERIMENTS
S.NO
1.
2.a.
2.b.
2.c.
2.d.
2.e.
3.a.
3.b.
3.c.
3.d.
3.e.
4.a.
4.b.
5.a.
5.b.
5.c.
5.d.
5.e.
5.f.
6.a.
6.b.
6.c.
7.a.
7.b.
7.c.
8.a.
8.b.
8.c.
9.a.
9.b.
9.c.
9.d.
TITLE OF EXPERIMENTS
STUDY OF OS LINUX COMMANDS
2. SHELL PROGRAMMING
BIGGEST OF TWO NUMBERS
LEAP YEAR OR NOT
EVEN OR ODD NUMBER
SUM OF DIGITS
FIBONACCI SERIES
3 . SYSTEM CALLS
CREATE A CHILD PROCESS USING FORK
FORK AND WAIT SYSTEM CALL
CREATE A CHILD PROCESS USING SLEEP
DIRECTORY SYSTEM CALL
FILE SYSTEM CALL USING OPEN AND CLOSE
4 . SIMULATION OF LINUX COMMANDS
SIMULATION OF GREP
SIMULATION OF ls COMMAND
5 . PROCESSES SCHEDULING
IMPLEMENTATION OF FCFS SCHEDULING
IMPLEMENTATION OF SJF SCHEDULING ZERO ARRIVALTIME
IMPLEMENTATION OF SJF SCHEDULING NON ZERO ARRIVALTIME
IMPLEMENTATION OF PRIORITY SCHEDULING ZERO ARRIVALTIME
IMPLEMENTATION OF PRIORITY SCHEDULING NON ZERO ARRIVALTIME
IMPLEMENTATION OF RR SCHEDULING
6 . SEMAPHORE
PRODUCER AND CONSUMER PROBLEM
DINING PHILOSOPHER'S PROBLEM
READERS WRITER PROBLEM USING SEMAPHORE
7 . MEMORY MANAGEMENT
IMPLEMENTATION OF FIRST FIT
IMPLEMENTATION OF BEST FIT ALGORITHM
IMPLEMENTATION OF WORST FIT
8 . PAGE REPLACEMENT
FIFO PAGE REPLACEMENT ALGORITHM
LRU PAGE REPLACEMENT ALGORITHM
OPTIMAL PAGE REPLACEMENT ALGORITHM
9 . DISK SCHEDULING
FCFS
SSTF
SCAN
C-SCAN
DEPARTMENT OF CSE
EX.NO.1
DATE:
AIM:
To study the basic commands in Linux.
COMMANDS:
1. Calendar
NAME
(i) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: calendar
: cal
: Displays a simple calendar. If arguments are not
Specified, the current month is displayed.
: cal
:
Su
1
8
15
22
29
(ii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
Su Mo
1 2
8 9
15 16
22 23
29 30
Su Mo
1 2
8 9
15 16
22 23
29 30
January
Tu We Th
3 4 5
10 11 12
17 18 19
24 25 26
31
April
Tu We Th
3 4 5
10 11 12
17 18 19
24 25 26
Fr
6
13
20
27
Fr
6
13
20
27
Mo
2
9
16
23
30
June 2014
Tu We Th
3 4
5
10 11 12
17 18 19
24 25 26
Sa
7
14
21
28
: cal year
: Displays calendar of that year
: cal 2012
:
Sa Su Mo
7
14 5 6
21 12 13
28 19 20
26 27
Sa
7
14
21
28
Fr
6
13
20
27
February
Tu We Th
1
2
7 8
9
14 15 16
21 22 23
28 29
Su Mo Tu
1
6 7 8
13 14 15
20 21 22
27 28 29
May
We Th
2 3
9 10
16 17
23 24
30 31
Fr
3
10
17
24
Fr
4
11
18
25
Sa
4
11
18
25
March
Su Mo Tu We Th
1
4 5 6 7 8
11 12 13 14 15
18 19 20 21 22
25 26 27 28 29
Fr
2
9
16
23
30
Sa
3
10
17
24
31
Sa
5
12
19
26
June
Su Mo Tu We Th Fr
1
3 4
5 6 7 8
10 11 12 13 14 15
17 18 19 20 21 22
24 25 26 27 28 29
Sa
2
9
16
23
30
DEPARTMENT OF CSE
Su Mo
1 2
8 9
15 16
22 23
29 30
Tu
3
10
17
24
31
Su Mo
1
7 8
14 15
21 22
28 29
Tu
2
9
16
23
30
July
We
4
11
18
25
Th
5
12
19
26
Fr
6
13
20
27
Sa
7
14
21
28
August
Su Mo Tu We Th
1 2
5 6 7 8 9
12 13 14 15 16
19 20 21 22 23
26 27 28 29 30
Fr
3
10
17
24
31
Sa
4
11
18
25
October
We Th
3 4
10 11
17 18
24 25
31
Fr
5
12
19
26
Sa
6
13
20
27
November
Su Mo Tu We Th
1
4 5
6 7 8
11 12 13 14 15
18 19 20 21 22
25 26 27 28 29
Fr
2
9
16
23
30
Sa
3
10
17
24
September
Su Mo Tu We Th Fr Sa
1
2 3
4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
December
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Su Mo
1 2
8 9
15 16
22 23
29 30
July
Tu We
3 4
10 11
17 18
24 25
31
Th
5
12
19
26
Fr
6
13
20
27
Sa
7
14
21
28
(iv)SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
Su Mo
5
12
19
26
6
13
20
27
August
Tu We Th
1 2
7 8 9
14 15 16
21 22 23
28 29 30
Fr
3
10
17
24
31
Sa
4
11
18
25
September
Su Mo Tu We Th Fr Sa
1
2 3
4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
2. Date
NAME
(i) SYNTAX
DESCRIPTION
OUTPUT
DEPARTMENT OF CSE
(ii) SYNTAX
DESCRIPTION
OUTPUT
: date +% H
: Display the current hour.
: 12
(iii) SYNTAX
DESCRIPTION
OUTPUT
: date +% h
: Display the current month name.
: Jul
(iv) SYNTAX
DESCRIPTION
OUTPUT
: date +% m
: Display the current month number.
:7
(v) SYNTAX
DESCRIPTION
OUTPUT
: date +% a
: Display the abbreviated weekday name.
: Mon
(vi) SYNTAX
DESCRIPTION
OUTPUT
: date +% y
: Display the current year.
: 12
(vii) SYNTAX
DESCRIPTION
OUTPUT
: date +% S
: Display the current second.
: 57
3. Script
NAME
: SCRIPT makes typescript of terminal session
DESCRIPTION : Makes a typescript of everything printed on your terminal. It is useful
for students who need a hardcopy record of an interactive session as
proof of an assignment, as the typescript file can be printed out later
with lpr(1).
SYNTAX
: script scriptname
..
..
..
Exit
OPENING A SCRIPT:
SYNTAX
: vi scriptname
EXAMPLE
: vi date.txt
OUTPUT
: ~date
~ Mon Jul 23 12:17:50 IST 2012
~
~
INSERT
P a g e | 6 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
4. ls
NAME
(i) SYNTAX
DESCRIPTION
OUTPUT
(ii) SYNTAX
: ls l
DESCRIPTION : Displays files in long listing format.
OUTPUT
:
csea08
csea08
1384962
Jul 23 12:17 [23.07.2012]
csea08
csea08
20325
Jul 23 12:30 [23.07.12]
csea08
csea08
138
Jul 23 12:33 [01;32case.sh]
csea08
csea08
13830
Jul 23 12:37 [01;34cse]
csea08
csea08
183
Jul 23 12:40 [01;32mdigit.sh]
csea08
csea08
530
Jul 23 12:50 [01;32memp.sh]
csea08
csea08
730
Jul 23 12:59 [01;32mgreatest.sh]
(iii) SYNTAX
: ls -r
DESCRIPTION : Displays the files in reverse sorted order.
OUTPUT
:
num.sh
mouse.txt
greatest.sh
digit.sh
cse.txt
case.sh
emp.sh
(iv) SYNTAX
: ls -s
DESCRIPTION : Displays the size of each files.
OUTPUT
:
8 num.sh
4 mouse.txt 8 greatest.sh 8 emp.sh
8 digit.sh
4 cse.txt
8 case.sh
(v) SYNTAX
: ls -S
DESCRIPTION : Displays the files in sorted order.
OUTPUT
:
case.sh
cse.txt
digit.sh
greatest.sh mouse.txt
num.sh
5. cp
NAME
SYNTAX
DESCRIPTION
EXAMPLE
emp.sh
6. rm
NAME
SYNTAX
DESCRIPTION
EXAMPLE
: rm remove files
: rm filename
: This command removes each specified file.
: rm cse.txt
DEPARTMENT OF CSE
7. mv
NAME
SYNTAX
DESCRIPTION
EXAMPLE
: mv move(rename) files
: mv f1 f2
: Renames Source to Destination
: mv new.txt cse.txt
8. mkdir
NAME
SYNTAX
DESCRIPTION
EXAMPLE
9. rmdir
NAME
SYNTAX
DESCRIPTION
EXAMPLE
10. Pwd
: pwd Present Working Directory displays the name of the
current/working directory
SYNTAX
: pwd
DESCRIPTION : Displays the name of the current/working directory
OUTPUT
: \home\csea08\new
NAME
11. Cd
NAME
: cd Change Directory
(i) SYNTAX
: cd dirname
DESCRIPTION : Change the directory which we use to work with.
EXAMPLE
: cd New
(ii) SYNTAX
: cd ..
DESCRIPTION : Quits from the current directory.
(iii) SYNTAX
: cd\
DESCRIPTION : Returns to the home directory.
12. Cat
NAME
(i) SYNTAX
DESCRIPTION
EXAMPLE
: cat- concatenate & open files and print on the standard output
: cat > filename
: This command is used to open a new file.
: cat > a.txt
DEPARTMENT OF CSE
OUTPUT
:
NAME : ZZZZ
ROLL NO: XX
(ii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: cat filename
: To view the contents of the file.
: cat a.txt
:
NAME : ZZZZ
ROLL NO: XX
(iii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: cat f1 f2 > f3
: To concatenate f1 and f2 save in f3
: cat a.txt b.txt > c.txt
:
a.txt=>
NAME : ZZZZ
ROLL NO: XX
b.txt=>
COLLEGE.SMVEC
c.txt=>
NAME : ZZZZ
ROLL NO: XX
COLLEGE.SMVEC
(iv) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: cat n filename
: To display the contents of the file along with the line numbers.
: cat -n sample.txt
: 1 hai
2 how are u?
(v) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: cat f1 >> f2
: To redirect the data from one file to another.
: cat sample.txt new.txt
: cat new.txt
sample. txt=>
hai
how are u?
new. txt=>
hai
how are u?
13. Whoami
NAME
SYNTAX
DEPARTMENT OF CSE
OUTPUT
: csea08
14. Man
NAME
SYNTAX
DESCRIPTION
EXAMPLE
15. Head
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: head
: head filename
: Displays the first ten lines in the file.
: head fruits.txt
: apple
banana
cherry
jack fruit
strawberry
orange
pineapple
mango
grape
papaya
16. Tail
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: tail
: tail filename
: Displays the last ten lines in the file.
: tail fruits.txt
: apple
banana
cherry
jack fruit
strawberry
orange
pineapple
mango
grape
papaya
17. Clear
NAME
: clear
SYNTAX
: clear
DESCRIPTION : Clears the content of the command prompt.
DEPARTMENT OF CSE
18. Sort
NAME
(i) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: sort
: sort filename
: Sorts the content of the file in ascending order.
: sort names.txt
:
Arun
Balu
Chandra
David
Edwards
(ii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: sort r filename
: Sorts the content of the file in descending order.
: sort r names.txt
:
Edwards
David
Chandra
Balu
Arun
19. Who
NAME
SYNTAX
DESCRIPTION
OUTPUT
: who
: who
: Displays all the users currently logged it.
:
csea13 pts/1
Jul 23 10:08 (172.17.22.38)
csea06 pts/10
Jul 23 10:13 (172.17.21.11)
csea12 pts/12
Jul 23 10:13 (172.17.21.35)
csea18 pts/11
Jul 23 10:13 (172.17.20.9)
csea24 pts/8
Jul 23 10:14 (172.17.22.33)
csea05 pts/13
Jul 23 10:15 (172.17.21.36)
root :0
Jul 23 10:20
csea20 pts/16
Jul 23 10:22 (172.17.21.43)
csea11 pts/20
Jul 23 10:28 (172.17.21.27)
csea23 pts/5
Jul 23 10:37 (172.17.22.14)
csea03 pts/0
Jul 23 10:37 (172.17.222.37)
csea01 pts/4
Jul 23 11:00 (172.17.22.13)
csea21 pts/15
Jul 23 11:00 (172.17.21.34)
csea07 pts/18
Jul 23 11:00 (172.17.20.28)
csea08 pts/14
Jul 23 11:01 (172.17.22.16)
csea16 pts/7
Jul 23 11:01 (172.17.21.24)
csea02 pts/19
Jul 23 11:01 (172.17.21.45)
staff pts/26
Jul 23 12:20 (172.17.21.21)
20. Finger
NAME
: finger
SYNTAX
: finger
DESCRIPTION : Displays the detailed information about the system users.
P a g e | 11 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
OUTPUT
:
Login Name
Tty Idle Login Time Office Office Phone
csea01
pts/4
2 Jul 23 11:00 (172.17.22.13)
csea02 csea02 pts/19
2 Jul 23 11:01 (172.17.21.45)
csea03
pts/0
Jul 23 10:37 (172.17.222.37)
csea05
pts/13
Jul 23 10:15 (172.17.21.36)
csea06
pts/10
Jul 23 10:13 (172.17.21.11)
csea07
pts/18
Jul 23 11:00 (172.17.20.28)
csea08
pts/14
Jul 23 11:01 (172.17.22.16)
csea09
pts/3
Jul 23 12:13 (172.17.22.115)
csea10
pts/2
1 Jul 23 12:08 (172.17.22.26)
csea11
pts/20
1 Jul 23 10:28 (172.17.21.27)
csea12
pts/12
1 Jul 23 10:13 (172.17.21.35)
csea13
pts/1
1 Jul 23 10:08 (172.17.22.38)
csea14
pts/21
Jul 23 11:01 (172.17.22.29)
csea15
pts/9
Jul 23 11:25 (172.17.22.130)
root
root
*:0
Jul 23 10:20
staff
pts/26
1 Jul 23 12:20 (172.17.21.21)
21. Last
NAME
SYNTAX
DESCRIPTION
OUTPUT
: last
: last
: Displays the list of last logged-in users for a month.
:
staff pts/26
172.17.21.21 Mon Jul 23 12:20 still logged in
csea09 pts/3
172.17.22.115 Mon Jul 23 12:13 still logged in
csea04 pts/23
172.17.22.60 Mon Jul 23 12:12 - 12:18 (00:05)
csea23 pts/25
172.17.22.60 Mon Jul 23 12:11 - 12:11 (00:00)
csea10 pts/2
172.17.22.26 Mon Jul 23 12:08 still logged in
csea04 pts/23
172.17.22.60 Mon Jul 23 11:51 - 11:52 (00:00)
csea08 pts/23
172.17.22.60 Mon Jul 23 11:50 - 11:51 (00:01)
csea04 pts/23
172.17.22.60 Mon Jul 23 11:48 - 11:50 (00:01)
csea06 pts/23
172.17.22.60 Mon Jul 23 11:46 - 11:47 (00:01)
csea23 pts/6
172.17.22.14 Mon Jul 23 11:45 still logged in
csea09 pts/3
172.17.22.14 Mon Jul 23 11:44 - 11:45 (00:01)
csea09 pts/6
172.17.22.115 Mon Jul 23 11:38 - 11:42 (00:04)
reboot system boot 2.4.20-8smp
Mon Jul 23 08:57
(03:24)
wtmp begins Mon Jul 2 10:08:30 2012
22. And
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: and - &&
: cmd1 && cmd2
: Used to combine more than one commands.
: whoami && date
: csea23
Mon Jul 23 12:22:54 IST 2012
DEPARTMENT OF CSE
23. Or
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
24. . Alias
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
25. Edit
NAME
SYNTAX
DESCRIPTION
EXAMPLE
: or - ||
: cmd1 || cmd2
: Displays the output for one command which is true.
: whoami || date
: csea23
: alias
: alias name="value"
: To create simple names or abbreviations for commands
: alias p="pwd"
p
: /home/mca1
: edit
: vi filename
: Edits the content of the file. To edit press I and to save press esc:wq
: vi names.txt
26. cut
NAME
: cut
(i) SYNTAX
: cut OPTION -m [FILE]...
DESCRIPTION
: extracts m characters from the beginning of each line from the specified file.
EXAMPLE
: cut c -3 test.txt
OUTPUT
:
BEFORE EXECUTION : cat > test.txt
Smvec
manakula
vinayagar
AFTER EXECUTION : smv
man
vin
27. Touch
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: touch
: touch filename
: Creates an empty file.
: touch hello.txt
:
BEFORE EXECUTION : ls
Sample.txt
AFTER EXECUTION
welcome.txt
: ls
Sample.txt
welcome.txt
hello.txt
DEPARTMENT OF CSE
28. Uniq
NAME
SYNTAX
DESCRIPTION
EXAMPLE
: uniq
: uniq option filename1 filename2
: Discard all but one of successive identical lines from filename1 to filename2
: uniq d a.txt b.txt
OUTPUT
BEFORE EXECUTION
AFTER EXECUTION
29. Semicolon
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: Semicolon (;)
: cmd1 ; cmd2; cmd3
: Similar to and command which combines more than one command.
: whoami && date
: csea23
Mon Jul 23 12:22:54 IST 2012
30. Echo
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: wc word count
: wc filename
: Displays the number of lines, words and characters in files.
: wc a.txt
: a.txt=>
hai
how are u
2 lines, 4 words, 12 characters.
(ii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: wc -l filename
: Displays the number of lines in files.
: wc l a.txt
: a.txt=>
hai
how are u
DEPARTMENT OF CSE
2 lines
(iii) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: wc -m filename
: Displays the number of characters in files.
: wc m a.txt
: a.txt=>
hai
how are u
12 characters
(iv) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: wc -w filename
: Displays the number of words in files.
: wc w a.txt
: a.txt=>
hai
how are u
4 words
32. Grep
NAME
(i) SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: grep
: grep pattern filename
: To search for a regular expression or a pattern in a file
: grep apple b.txt
: b.txt=>
This is an apple
This is a fruit
apple
(ii) SYNTAX
: grep c pattern filename
DESCRIPTION : To search for a regular expression or a pattern in a file and displays
how many times that pattern is repeated in the file.
EXAMPLE
: grep c apple b.txt
OUTPUT
: b.txt=>
This is an apple
This is a fruit
1
(iii) SYNTAX
: grep n pattern filename
DESCRIPTION : To search for a regular expression or a pattern in a file and displays
the searched content along with the line and line number, if found.
EXAMPLE
: grep n apple b.txt
OUTPUT
: b.txt=>
This is an apple
This is a fruit
1: apple
DEPARTMENT OF CSE
(iv) SYNTAX
: grep i pattern filename
DESCRIPTION : To search for a regular expression or a pattern in a file irrespective of
the case.
EXAMPLE
: grep n APPLE a.txt
OUTPUT
: b.txt=>
This is an apple
This is a fruit
apple
33. Read
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
34. Fgrep
NAME
(i)SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: fgrep
: fgrep pattern f1 f2
: To search for a regular expression or a pattern in two files
: fgrep hai a.txt d.txt
: a.txt=>
hai
how are u
d.txt=>
this is a file
the type of the file is text
a.txt: hai
(ii) SYNTAX
: fgrep c pattern f1 f2
DESCRIPTION : To search for a regular expression or a pattern in two files and
displays how many times that pattern is repeated in the files.
EXAMPLE
: fgrep c file a.txt d.txt
OUTPUT
: a.txt=>
hai
how are u
d.txt=>
this is a file
the type of the file is text
a.txt : 0
d.txt : 2
(iii) SYNTAX
: fgrep n pattern f1 f2
DESCRIPTION : To search for a regular expression or a pattern in two files and
P a g e | 16 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
EXAMPLE
OUTPUT
displays the searched content along with the line and line number, if
found.
: fgrep c file a.txt d.txt
: a.txt=>
hai
how are u
d.txt=>
this is a file
the type of the file is text
d.txt : 1 : this a file
d.txt : 2 : the type of the file is text
(iv) SYNTAX
: fgrep i pattern f1 f2
DESCRIPTION : To search for a regular expression or a pattern in two files
irrespective of the case.
EXAMPLE
: fgrep c HaI a.txt d.txt
OUTPUT
: a.txt=>
hai
how are u
d.txt=>
this is a file
the type of the file is text
a.txt : hai
35. Pipe
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: Pipe - |
: cmd1 | cmd2 | cmd3
: Makes the output of one command as input for another command.
: date | wc -w
:6
36. Tee
NAME
: Tee
SYNTAX
: cmd1 | tee filename
DESCRIPTION : Used to read the standard input and then write to standard output or
file.
EXAMPLE
: date | tee f.txt | wc -w
OUTPUT
:6
37. Write
NAME
SYNTAX
DESCRIPTION
EXAMPLE
: write
: write login_name
: Used to communicate with other logged in users.
: write csea25
DEPARTMENT OF CSE
38. Mail
NAME
(i) SYNTAX
DESCRIPTION
EXAMPLE
: Mail
: mail login_name
: Used to send mail to a user.
: write csea25
(ii) SYNTAX
: mail
DESCRIPTION : Used to view the mails in the mailbox.
39. Terminal Name
NAME
SYNTAX
DESCRIPTION
OUTPUT
: tty
: tty
: Used to display the terminal path name.
: /dev/pts/23
40. Expression
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: expr
: `expr expression`
: Used to evaluate an expression
: echo `expr 10 + 10`
: 20
41. . free
NAME
SYNTAX
DESCRIPTION
: free
: free
: Displays the total amount of free and used physical and swap memory in the
system
EXAMPLE
: free
OUTPUT
:
[mca1@redhat ~]$ free
total
used
free
shared buffers cached
Mem:
1016820 647688 369132
0
59916
414316
-/+ buffers/cache: 173456 843364
Swap:
2064380
0 2064380
42. Find
ping
NAME
(i) SYNTAX
DESCRIPTION
: ping
: ping Ip-address
: Ping is used diagnostically to ensure that a host computer the user is trying to
reach is actually operating.
EXAMPLE
: ping 172.17.10.111
OUTPUT
:
[mca1@redhat ~]$ ping 172.17.10.111
PING 172.17.10.111 (172.17.10.111) 56(84) bytes of data.
P a g e | 18 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
43. Password
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: Password
: passwd
: Used to change the password.
: passwd
: Changing password for user csea09.
Changing password for csea09
(current) UNIX password:
New password:
44.Exit
NAME
: Logout
SYNTAX
: logout
DESCRIPTION : Used to logout.
45.Uname
NAME
SYNTAX
DESCRIPTION
OUTPUT
: Uname
: uname
: Used to display the name of the system being used.
: Linux
46. Sequence
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
1
2
3
4
: seq
: seq starting_value ending_value
: print a sequence of numbers
: seq 1 4
:
DESCRIPTION : Used to open a file and position the cursor at the first line.
EXAMPLE
: vi +b.txt
OUTPUT
:
P a g e | 19 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
hi bala
:wq
"new.txt" 7L, 42C written
48. Compare
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: Compare
: comm filename1 filename2
: Compares the sorted files line by line.
: comm a.txt b.txt
: OS is a program that acts as an interface.
49. Type
NAME
SYNTAX
DESCRIPTION
EXAMPLE
OUTPUT
: Type
: type filename
: To view the content of the file.
: type names.txt
:
Arun
Balu
Chandra
David
Edwards
: Basic Calculator
: bc
: To open the basic calculator.
: bc
: 10 + 10
20
RESULT:
Thus all the Linux commands are executed.
DEPARTMENT OF CSE
EX.NO.2
DATE:
SHELL PROGRAMMING
AIM:
To write various shell programming.
BIGGEST OF TWO NUMBERS
ALGORITHM:
1. Start the program.
2. Enter the value for a & b.
3. If a is greater than b then goto step 3 else goto step 4.
4. Print a is greate goto step 6.
5. Print b is greate goto step 6.
6. Stop the program execution.
PROGRAM:
clear
echo "enter the value of a & b"
read a
read b
if [$a -gt $b]
then
echo "A is Greater"
else
echo "B is Greater "
fi
OUTPUT:
Enter the value of a & b
8
9
B is big
DEPARTMENT OF CSE
AIM:
To find whether the given year is a leap year or not.
ALGORITHM:
1. Start the program.
2. Enter the value for year.
3. Divide year by 4.Check the remainder.If the remainder is equal to zero goto step 4 else goto step 5.
4. Print the given year is leap year goto step 6.
5. Print the given year is not a leap year goto step 6.
6. Stop the program execution.
PROGRAM:
clear
echo "enter year"
read year
if [ ` expr $year % 4` -eq 0 ]
then
echo "$year is leap year"
else
echo "$year is not leap year"
fi
OUTPUT:
Enter year
2004
2004 is leap year
Enter year
2005
2005 is not leap year
DEPARTMENT OF CSE
OUTPUT:
Enter the number
5
0 is a even number
1 is a odd number
2 is a even number
3 is a odd number
4 is a even number
DEPARTMENT OF CSE
SUM OF DIGITS
AIM:
To find the sum of digits of a given number.
ALGORITHM:
1. Start the program.
2. Get the value for num.
3. Initialize the variable s=0.
4. Check whether n is not equal to zero, if so extract the digit one by one by doing the following
steps.otherwise goto step 6.
n1=` expr $num % 10`
s=` expr $s + $n1`
num=` expr $num / 10`
5. Goto step 4.
6. Print the value of sum of digit.
7. Stop the program execution.
PROGRAM:
clear
echo "Enter the value for num"
read num
s=0
while [ $num -ne 0 ]
do
n1=` expr $num % 10`
s=` expr $s + $n1`
num=` expr $num / 10`
done
echo "sum of digits:$s"
OUTPUT:
Enter digits
123
Sum of digits:6
DEPARTMENT OF CSE
FIBONACCI SERIES
AIM:
To write a program to generate a fibonnacci series.
ALGORITHM:
1. Start the program.
2. Get the value of num to generate the fibonnacci series.
3. Initialize a=-1,b=1, and c=0.
4. Check if the num is greater than 0, Add a and b value to store value into c variable goto step 5
else goto step 8.
5. Store the value of b to a, and c to b.
6. Decrement the value n by 1.
7. Print the value of c goto step 4.
8. Stop the program.
PROGRAM:
clear
echo "Enter the number"
read num
a=-1
b=1
c=0
echo "Fibnoci series"
while [ $num -gt 0 ]
do
c=` expr $a + $b`
a=$b
b=$c
num=` expr $num - 1`
echo $c
done
OUTPUT:
Enter the number
5
Fibonacci series
0
1
1
2
3
RESULT:
Thus the various shell programs has been entered and verified
DEPARTMENT OF CSE
EX.NO.3
DATE:
AIM:
To write various system calls.
CREATE A CHILD PROCESS USING FORK
ALGORITHM:
1. Start the program.
2. Cerate a child process by assigning Pid=fork ().
3. If Pid =0 ,the child process successfully created ,print the child process id goto step 4
4. If Pid >0, then the parent process executed and print the parent process id goto step 6 else goto
step 5.
5. Print fork () process is not executed goto step 6.
6. Stop the process.
PROGRAM:
#include<stdio.h>
main()
{
int pid;
pid=fork();
printf("\n HELLO \n");
if(pid==0)
{
printf("\n CHILD PROCESS IS EXECUTED \n");
printf("\n THE ID NUMBER OF THE CHILD PROCESS IS %d \n",getpid());
}
else if(pid>0)
{
printf("\n PARENT PROCESS IS EXECUTED");
printf("\n THE ID NUMBER OF PARENT PROCESS IS %d\n",getppid());
}
else
printf("\n FORK PROCESS IS NOT EXECUTED");
}
OUTPUT:
[iiiit01@localhost cpro]$ cc pro2.c
[iiiit01@localhost cpro]$ ./a.out
HELLO
CHILD PROCESS IS EXECUTED
THE ID NUMBER OF THE CHILD PROCESS IS 3128
HELLO
PARENT PROCESS IS EXECUTED
THE ID NUMBER OF PARENT PROCESS IS 2964
P a g e | 26 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
OUTPUT:
[iiiit01@localhost cpro]$ cc pro3.c
[iiiit01@localhost cpro]$ ./a.out
HELLO
CHILD PROCESS IS EXECUTED
THE ID NUMBER OF THE CHILD PROCESS IS 3150
HELLO
PARENT PROCESS IS EXECUTED
THE ID NUMBER OF PARENT PROCESS is 3149
DEPARTMENT OF CSE
OUTPUT:
[iiiit01@localhost cpro]$ cc pro4.c
[iiiit01@localhost cpro]$ ./a.out
HELLO
CHILD PROCESS IS CREATED
THE ID NUMBER OF THE CHILD PROCESS IS 3206
HELLO
PARENT PROCESS IS RUNNING
THE ID NUMBER OF PARENT PROCESS IS 2964
DEPARTMENT OF CSE
OUTPUT:
[iiiit01@localhost cpro]$ cc pro1.c
[iiiit01@localhost cpro]$ mkdir hiram
[iiiit01@localhost cpro]$ ./a.out hiram
DEPARTMENT OF CSE
DEPARTMENT OF CSE
OUTPUT:
[iiiit01@localhost cpro]$ cc pro5.c
[iiiit01@localhost cpro]$ vi output
Hi how are u
[iiiit01@localhost cpro]$. /a.out output peruout
File completed
[iiiit01@localhost cpro]$ Cat peruout
Hi how are u
RESULT:
Thus the various system calls has been entered and verified
DEPARTMENT OF CSE
EX.NO.4
SIMULATION OF GREP
DATE:
AIM:
To write a c program to simulate the Linux command grep.
ALGORITHM:
1.
2.
3.
4.
5.
DEPARTMENT OF CSE
OUTPUT:
ENTER THE PATTERN: PCET
THE PATTERN IS FOUND
ENTER THE PATTERN: PARK
THE PATTERN IS NOT FOUND
RESULT:
Thus a C program to simulate grep command of Unix is written and executed successfully.
DEPARTMENT OF CSE
SIMULATION OF ls COMMAND
AIM:
To write a C program to simulate ls command used in Unix.
Algorithm:
1.
2.
3.
4.
5.
6.
PROGRAM:
#include<dirent.h>
#include<sys/stat.h>
main()
{
DIR *dp;
struct dirent *dir;
char d[10];
printf("enter the directory name");
scanf("%s" ,d);
dp=opendir(d);
if(dp!=NULL)
{
while((dir=readdir(dp))!=NULL)
printf(" %s \n ",dir->d_name);
}
else
printf("\n no such directory found");
closedir(dp);
exit(0);
}
OUTPUT:
Enter the directory name:s05cse15
F1
F2
Vc++
C
RESULT:
Thus a C program to simulate ls command of Unix is written and executed successfully.
P a g e | 34 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
EX.NO.5
PROCESS SCHEDULING
DATE:
IMPLEMENTATION OF FCFS SCHEDULING
AIM:
To write a c program to implement FCFS scheduling.
ALGORITHM:
1: start the program.
2: with burst time, execution time ,arrival Time, waiting time and turnaround time and create object
for the structure
3: In main function get the number of processes and burst time arrival time for each processes.
4: calculate the execution time by using the following loop.
Initially first process execution is zero.
Next processes execution =previous processes execution
time + previous process burst time.
5: waiting time and turn around time can be calculated by
WAITING TIME=EXECUTIONTIME-ARRIVAL TIME.
TURNARROUND TIME=WAITING TIME+BURST TIME.
6: Average waiting time and average turn around can be Calculated by
Average waiting time=sum of waiting time /No of process.
Average Turnaround time= sum of Turnaround time/ No of processes.
7: Print processes Burst time Arrival time Waiting time Turnaround time for each processes and
Average waiting and Turnaround time.
8 : Terminate the program.
PROGRAM:
#include<stdio.h>
struct fc
{
int bst,wt,tat,ar,exu;
}p[10];
main()
{
int pro,i;
float awt=0,atat=0;
printf("\nENTER NUMBER OF PROCESS\n");
scanf("%d",&pro);
printf("\nENTER BURST TIME FOR EACH PROCESS\n");
for(i=0;i<pro;i++)
{
scanf("%d",&p[i].bst);
}
printf("\nENTER ARRAIVAL TIME FOR EACH PROCESS\n");
for(i=0;i<pro;i++)
{
scanf("%d",&p[i].ar);
P a g e | 35 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
}
p[i].exu=0;
for(i=0;i<pro;i++)
{
p[i+1].exu=(p[i].exu+p[i].bst);
}
for(i=0;i<pro;i++)
{
p[i].wt=p[i].exu-p[i].ar;
p[i].tat=p[i].wt+p[i].bst;
}
for(i=0;i<pro;i++)
{
awt=awt+p[i].wt;
atat=atat+p[i].tat;
}
printf("\nPROCESS BRUSTTIME ARRIVALTIME WAITINGTIME
TURNARROUNDTIME");
for(i=0;i<pro;i++)
{
printf("\np %d
%d
%d
%d
%d ",i+1,p[i].bst,p[i].ar,p[i].wt,p[i].tat);
}
printf("\nAVERAGE WAITING TIME= %f",awt/pro);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/pro);
return 0;
}
OUTPUT:
ENTER NUMBER OF PROCESS
5
ENTER BURST TIME FOR EACH PROCESS
8
3
4
2
6
ENTER ARRAIVAL TIME FOR EACH PROCESS
0
0
0
0
0
DEPARTMENT OF CSE
PROCESS
p0
p1
p2
p3
p4
BRUSTTIME
8
3
4
2
6
ARRIVALTIME
0
0
0
0
0
WAITINGTIME
0
8
11
15
17
TURNARROUNDTIME
8
11
15
17
23
RESULT:
The the C program to implement FCFS scheduling has been executed successfully and the output has
been verified.
DEPARTMENT OF CSE
DEPARTMENT OF CSE
for(j=i+1;j<n;j++)
{
if(a[i].bst>a[j].bst)
{t=a[i].bst;
a[i].bst=a[j].bst;
a[j].bst=t;
k=a[i].pro;
a[i].pro=a[j].pro;
a[j].pro=k;
}}}
a[0].exu=0;
for(i=0;i<n;i++)
a[i+1].exu=a[i].exu+a[i].bst;
for(i=0;i<n;i++)
{
a[i].wt=a[i].exu;
a[i].tat=a[i].wt+a[i].bst;
}
for(i=0;i<n;i++)
{
awt=awt+a[i].wt;
atat=atat+a[i].tat;
}
printf("\nPROCESS BRUSTTIME WAITINGTIME
TURNARROUNDTIME");
for(i=0;i<n;i++)
{
printf("\np %d
%d
%d
%d ",a[i].pro,a[i].bst,a[i].wt,a[i].tat);
}
printf("\nAVERAGE WAITING TIME= %f",awt/n);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/n);
return 0;
}
OUTPUT:
************ARRIVAL TIME IS ZERO**************
ENTER NUMBER OF PROCESS
4
ENTER BURST TIME FOR EACH PROCESS
6
8
7
3
PROCESS
p4
p1
p3
p2
BRUSTTIME
3
6
7
8
WAITINGTIME
0
3
9
16
TURNARROUNDTIME
3
9
16
24
DEPARTMENT OF CSE
DEPARTMENT OF CSE
a[i].pro=i+1;
a[i].bst=p[i].bst;
a[i].ar=p[i].ar;
}
for(i=1;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i].bst>a[j].bst)
{
t=a[i].bst;
a[i].bst=a[j].bst;
a[j].bst=t;
k=a[i].pro;
a[i].pro=a[j].pro;
a[j].pro=k;
z= a[i].ar ;
a[i].ar=a[j].ar;
a[j].ar=z;
}
}
}
a[0].exu=0;
for(i=1;i<n;i++)
a[i].exu=a[i-1].exu+a[i-1].bst;
for(i=0;i<n;i++)
{
a[i].wt=a[i].exu-a[i].ar;
a[i].tat=a[i].wt+a[i].bst;
}
for(i=0;i<n;i++)
{
awt=awt+a[i].wt;
atat=atat+a[i].tat;
}
printf("\nPROCESS BRUSTTIME ARRIVALTIME WAITINGTIME
TURNARROUNDTIME");
for(i=0;i<n;i++)
{
printf("\np %d
%d
%d
%d
%d ",a[i].pro,a[i].bst,a[i].ar,a[i].wt,a[i].tat);
}
printf("\nAVERAGE WAITING TIME= %f",awt/n);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/n);
return 0;
}
DEPARTMENT OF CSE
OUTPUT:
ENTER NUMBER OF PROCESS:
4
ENTER BURST TIME FOR EACH PROCESS
8
4
9
5
ENTER ARRAIVAL TIME FOR EACH PROCESS:
0
1
2
3
PROCESS
p1
p2
p4
p3
RESULT:
The C programs to implement non preemptive SJF scheduling with zero arrival time and non zero
arrival time has been executed successfully and the output has been verified.
DEPARTMENT OF CSE
DEPARTMENT OF CSE
ZERO ARRIVALTIME
PROGRAM:
#include<stdio.h>
struct fc
{
int bst,wt,tat,ar,exu,pro,pr;
}p[10],a[10],b[10];
main()
{
int n,i,j,t,k,z;
float awt=0,atat=0;
printf(" ************ARRIVAL TIME IS ZERO**************");
printf("\n*******LOW NUMBERS HAVE HIGH PRIORITY********");
printf("\nENTER NUMBER OF PROCESS\n");
scanf("%d",&n);
printf("\nENTER BURST TIME FOR EACH PROCESS\n");
for(i=0;i<n;i++)
scanf("%d",&p[i].bst);
printf("\nENTER PRIORITY FOR EACH PROCESS\n");
for(i=0;i<n;i++)
scanf("%d",&p[i].pr);
for(i=0;i<n;i++)
{
a[i].pro=i+1;
a[i].bst=p[i].bst;
a[i].pr=p[i].pr;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i].pr>a[j].pr)
{
z=a[i].pr;
a[i].pr=a[j].pr;
a[j].pr=z;
t=a[i].bst;
a[i].bst=a[j].bst;
a[j].bst=t;
k=a[i].pro;
a[i].pro=a[j].pro;
a[j].pro=k;
} } }
a[0].exu=0;
for(i=0;i<n;i++)
a[i+1].exu=a[i].exu+a[i].bst;
for(i=0;i<n;i++)
{
P a g e | 44 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
a[i].wt=a[i].exu;
a[i].tat=a[i].wt+a[i].bst;
}
for(i=0;i<n;i++)
{
awt=awt+a[i].wt;
atat=atat+a[i].tat;
}
printf("\n PROCESSES BRUSTTIME PRIORITY
WAITINGTIME TURNARROUNDTIME");
for(i=0;i<n;i++)
{
printf("\np %d
%d
%d
%d
%d ",a[i].pro,a[i].bst,a[i].pr,a[i].wt,a[i].tat);
}
printf("\nAVERAGE WAITING TIME= %f",awt/n);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/n);
return 0;
}
OUTPUT:
**************ARRIVAL TIME IS ZERO*****************
*******LOW NUMBERS HAVE HIGH PRIORITY********
ENTER NUMBER OF PROCESS
5
ENTER BURST TIME FOR EACH PROCESS
10
1
2
1
5
ENTER PRIORITY FOR EACH PROCESS
3
1
4
5
2
PROCESS
p2
p5
p1
p3
p4
BRUSTTIME
1
5
10
2
1
PRIORITY
1
2
3
4
5
WAITINGTIME
0
1
6
16
18
TURNARROUNDTIME
1
6
16
18
19
DEPARTMENT OF CSE
DEPARTMENT OF CSE
z= a[i].ar ;
a[i].ar=a[j].ar;
a[j].ar=z;
} } }
a[0].exu=0;
for(i=1;i<n;i++)
a[i].exu=a[i-1].exu+a[i-1].bst;
for(i=0;i<n;i++)
{
a[i].wt=a[i].exu-a[i].ar;
a[i].tat=a[i].wt+a[i].bst;
}
for(i=0;i<n;i++)
{
awt=awt+a[i].wt;
atat=atat+a[i].tat;
}
printf("\nPROCESS BRUSTTIME ARRIVALTIME PRIORITY
WAITINGTIME TURNARROUNDTIME");
for(i=0;i<n;i++)
{
printf("\np %d
%d %d %d %d %d",
a[i].pro,a[i].bst,a[i].ar,a[i].pr,a[i].wt,a[i].tat);
}
printf("\nAVERAGE WAITING TIME= %f",awt/n);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/n);
return 0;
}
OUTPUT:
*******LOW NUMBERS HAVE HIGH PRIORITY********
ENTER NUMBER OF PROCESS:
4
ENTER BURST TIME FOR EACH PROCESS:
6
5
3
5
ENTER ARRAIVAL TIME FOR EACH PROCESS:
0
1
2
3
ENTER PRIORITY FOR EACH PROCESS:
4
2
6
3
DEPARTMENT OF CSE
RESULT:
The c programs to implement non preemptive priority scheduling with zero arrival time and non zero
arrival time has been executed successfully and the output has been verified.
DEPARTMENT OF CSE
IMPLEMENTATION OF RR SCHEDULING
AIM:
To write a c program to implement Round Robin scheduling.
ALGORITHM:
1: start the program.
2: Declare a structure with burst time, execution time, arrival time ,waiting time, and turnaround time ,
variables and create Objects for that structure.
3: In main function get the number of processes , burst time,Arrival time for each process and time
slice.
4:store the burst time in temporary arrays.
5: Sort the burst time arrival time according to burst time and calculate maximum no of execution .
6: Execution time can be calculated by.
In two loops first loop for max no of execution second loop for noof process.
If burst time for each process greater than time slice do:
Temp var=Temp var+ time slice.
Execution time=Temp var.
Burst time=burst time time slice.
Else burst time less than time slice and greater than zero
Temp var =Temp var + burst time.
Execution time=Temp var.
Burst time=0.
7:Waiting time and turnaround time can be calculated by
WATING TIME=EXECUTION TIME-ARRIVAL TIME BRUST TIME
TURNARROUND TIME=WAITING TIME+BRUST TIME.
8: Average waiting time and average turn around can be Calculated by
Average waiting time=sum of waiting time /No of process.
Average Turnaround time= sum of Turnaround time/No of processes.
9: Print processes Burst time Arrival time waiting time
Turnaround time for each processes and Average waiting and Turnaround time.
10: Terminate the program.
PROGRAM:
#include<stdio.h>
struct fc
{
int bst,wt,tat,exu,n,ar;
}p[10],a[10],b[10];
main()
{
int pn,i,j,ts,t,x,y=0;
float awt=0,atat=0;
printf("\nENTER NUMBER OF PROCESS\n");
scanf("%d",&pn);
printf("\nENTER BURST TIME FOR EACH PROCESS\n");
for(i=0;i<pn;i++)
{
scanf("%d",&p[i].bst);
P a g e | 49 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
}
printf("\nENTER ARRAIVAL TIME FOR EACH PROCESS\n");
for(i=0;i<pn;i++)
{
scanf("%d",&p[i].ar);
}
printf("\nENTER THE TIME SLICE :");
scanf("%d",&ts);
for(i=0;i<pn;i++)
{
a[i].bst=p[i].bst;
b[i].bst=p[i].bst;
}
for(i=0;i<pn;i++)
{
for(j=i+1;j<pn;j++)
{
if(a[i].bst>a[j].bst)
{
t=a[i].bst;
a[i].bst=a[j].bst;
a[j].bst=t;
} } }
x=a[pn-1].bst/ts;
for(j=0;j<x+5;j++)
{
for(i=0;i<pn;i++)
{
if(p[i].bst>ts)
{
y=y+ts;
p[i].exu=y;
p[i].bst=p[i].bst-ts;
p[i].n=p[i].n+1;
}
else if(p[i].bst>0)
{
y=y+p[i].bst;
p[i].exu=y;
p[i].bst=0;
p[i].n=p[i].n+1;
} } }
for(i=0;i<pn;i++)
{
p[i].wt=p[i].exu-b[i].bst-p[i].ar;
p[i].tat=p[i].wt+b[i].bst;
}
for(i=0;i<pn;i++)
P a g e | 50 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
{
awt=awt+p[i].wt;
atat=atat+p[i].tat;
}
printf("\nPROCESS BRUSTTIME WAITINGTIME
TURNARROUNDTIME");
for(i=0;i<pn;i++)
{
printf("\np %d
%d
%d
%d ",i,b[i].bst,p[i].wt,p[i].tat);
}
printf("\nAVERAGE WAIRING TIME= %f",awt/pn);
printf("\nAVERAGE TURNARROUND TIME=%f",atat/pn);
return 0;
}
OUTPUT:
ENTER NUMBER OF PROCESS
3
ENTER BURST TIME FOR EACH PROCESS
24
3
3
ENTER ARRAIVAL TIME FOR EACH PROCESS
0
0
0
ENTER THE TIME SLICE :4
PROCESS BRUSTTIME ARRIVALTIME
p0
24
0
p1
3
0
p2
3
0
WAITINGTIME
6
4
7
TURNARROUNDTIME
30
7
10
DEPARTMENT OF CSE
BRUSTTIME
24
3
3
RESULT:
The C program to implement RR scheduling has been executed successfully and the output has been
verified.
DEPARTMENT OF CSE
EX.NO.6
SEMAPHORE
DATE:
AIM:
To write a c program to implement the following using semaphore
1. Producer and consumer problem
2. Dining philosopher's problem
3. Readers writer problem using semaphore
DEPARTMENT OF CSE
printf("full=%d\t empty=%d\n",full,empty);
}
void consumer()
{
int nextc;
printf("consumer\n");
wait(&full);
wait(&mutex);
nextc=buffer[out];
printf("consumerd item is %d\n",nextc);
out=(out+1)%5;
signal(&mutex);
signal(&empty);
printf("full=%d\t empty=%d\n",full,empty);
}
void wait(int *a)
{
while(*a<=0);
*a=*a-1;
}
void signal(int *b)
{
*b=*b+1;
}
main()
{
int c;
mutex=1;
empty=5;
full=0;
clrscr();
while(1)
{
printf("1.producer\t 2.consumer\t 3.both\t 4.Exit\n");
printf("choice\n");
scanf("%d",&c);
switch(c)
{
case 1:
if(empty==0)
printf("producer has to wait\n");
else
{
producer();
}
break;
case 2:
P a g e | 54 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
if(full==0)
printf("consumer has to wait");
else
{
consumer();
} break;
case 3:
if(!empty)
{
printf("producer has to wait\n");
consumer();
}
else if(!full)
{
printf("consumer has to wait\n");
producer();
}
else
{
consumer();
producer();
}
break;
case 4:
exit(0);
break;
}
}
getch();
return 0;
}
DEPARTMENT OF CSE
OUTPUT:
1.producer
2.consumer
choice
1
producer
produced item is 7
full=1 empty=4
3.both 4.Exit
1.producer
2.consumer
choice
1
producer
produced item is 1
full=2 empty=3
3.both 4.Exit
1.producer
2.consumer
choice
2
consumer
consumerd item is 7
full=1 empty=4
3.both 4.Exit
1.producer
2.consumer
choice
2
consumer
consumerd item is 1
full=0 empty=5
3.both 4.Exit
1.producer
2.consumer
3.both 4.Exit
choice
2
consumer has to wait1.producer 2.consumer
choice
1
producer
produced item is 3
full=1 empty=4
1.producer
2.consumer
choice
3
consumer
consumerd item is 3
full=0 empty=5
producer
produced item is 1
full=1 empty=4
3.both 4.Exit
1.producer
Choice
3.both 4.Exit
2.consumer
4
3.both 4.Exit
DEPARTMENT OF CSE
PROGRAM:
#include<stdio.h>
#include<conio.h>
char state[10],self[10],spoon[10];
void test(int k)
{
if((state[(k+4)%5]!='e')&&(state[k]=='h')&&(state[(k+1)%5]!='e'))
{
state[k]='e';
self[k]='s';
spoon[k]='n';
spoon[(k+4)%5]='n';
}
}
void pickup(int i)
{
state[i]='h';
test(i);
if(state[i]!='e')
self[i]='w';
}
void putdown(int i)
{
state[i]='t';
spoon[i]='s';
spoon[(i+4)%5]='s';
test((i+4)%5);
test((i+1)%5);
}
main()
{
int ch,a,n,i;
clrscr();
printf("\n Dining Philosopher's Problem:");
printf("\n...........................................\n");
P a g e | 57 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
for(i=0;i<5;i++)
{
state[i]='t';
self[i]='s';
spoon[i]='s';
}
printf("\n Initial state of each philososphers:");
printf("\n Phil No : \t Think/Eat \t Status \t Spoon");
for(i=0;i<5;i++)
printf("\n %d \t\t %c \t\t %c \t\t %c",i+1,state[i],self[i],spoon[i]);
printf("\n Enter the option : \n1.Exit \n 2.Hungry \n 3.Thinking \n");
printf("\n Enter your choice :");
scanf("%d",&ch);
while(ch!=1)
{
switch(ch)
{
case 1:
return 0;
case 2:
printf("\n Enter which philosophers is Hungry :");
scanf("%d",&n);
pickup(n-1);
break;
case 3:
printf("\n Enter which Philosopher is Thinking :");
scanf("%d",&n);
putdown(n-1);
break;
}
printf("\n State of each Philosepher :");
printf("\n Philno: \t Think/Eat \t Status \t Spoon");
for(i=0;i<5;i++)
printf("\n %d \t\t %c \t\t %c \t\t %c",i+1,state[i],self[i],spoon[i]);
printf("\n Enter the option : \n1.Exit \n 2.Hungry \n 3.Thinking \t :");
scanf("%d",&ch);
}
}
DEPARTMENT OF CSE
INPUT/OUTPUT
Dining Philosopher's Problem:
...........................................
Initial state of each philososphers:
Phil No :
Think/Eat
Status
1
t
s
2
t
s
3
t
s
4
t
s
5
t
s
Enter the option :
1.Exit
2.Hungry
3.Thinking
Spoon
s
s
s
s
s
Spoon
n
s
s
s
n
Spoon
n
s
s
s
n
DEPARTMENT OF CSE
Spoon
n
s
n
n
n
Spoon
n
s
n
n
n
Spoon
n
n
n
n
s
Spoon
n
n
s
n
n
DEPARTMENT OF CSE
Spoon
s
s
s
n
n
Spoon
s
s
s
s
s
DEPARTMENT OF CSE
DEPARTMENT OF CSE
{
wait(&wrt);
cout<<"\nEnter the string to write:";
gets(buffer);
cout<<"\nWriter writes:"<<buffer;
signal(&wrt);
}
void wait(int *x)
{
while(*x<=0);
*x=*x-1;
}
void signal(int *y)
{
*y=*y+1;
}
main()
{
mutex=1;
wrt=1;
readcount=0;
do
{
cout<<"\n\nREADER-WRITER PROBLEM\n\n1.READER\n2.WRITER\n3.READAND
WRITE\n4.WRITE AND READS\n5.EXIT\n\nENTER THE CHOCIE:";
cin>>ch;
switch(ch)
{
case 1:
reader();
break;
case 2:
writer();
break;
case 3:
reader();
writer();
break;
case 4:
writer();
reader();
break;
case 5:
exit(0);
}
}
while(ch<6);
getch();
}
P a g e | 63 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
OUTPUT
READER-WRITER PROBLEM
1.READER
2.WRITER
3.READAND WRITE
4.WRITE AND READS
5.EXIT
ENTER THE CHOCIE:1
READER READS:hello
READER-WRITER PROBLEM
1.READER
2.WRITER
3.READAND WRITE
4.WRITE AND READS
5.EXIT
ENTER THE CHOCIE:2
Enter the string to write:hi
REUSLT:
Thus the C program to implement semaphore has been entered and verified
DEPARTMENT OF CSE
EX.NO.7
MEMORY MANAGEMENT
DATE:
IMPLEMENTATION OF FIRST FIT
AIM:
To write a C program to implement first fit algorithm.
ALGORITHM:
1: start the program.
2: Declare a structure with memory size & process size as variables and create object for that
structure.
3: In main get the number and size of process and memory Partition.
4:compare process memory with memory partition if Process memory is less than memory partition
put the process into memory partition move to next process .
5:Continue the loop until all processes compare with memory partition.
6: Print process memory memory partition and memory allocation.
7: Terminate the program.
PROGRAM:
#include<stdio.h>
struct fc
{
int mem,po,pm;
}p[10];
main()
{
int n,i,j,x,t[10];
printf("\nENTER NUMBER OF MEMORY PARTISION:\n");
scanf("%d",&x);
printf("\nENTER THE SIZE OF MEMORY PARTISION:\n");
for(i=0;i<x;i++)
scanf("%d",&p[i].mem);
printf("\nENTER NUMBER OF PROCESS:\n");
scanf("%d",&n);
printf("\nENTER THE MEMORY SIZE FOR EACH PROCESS:\n");
for(i=0;i<n;i++)
scanf("%d",&p[i].pm);
for(i=0;i<x;i++)
t[i]=p[i].mem;
for(i=0;i<n;i++)
{
for(j=0;j<x;j++)
{
if(p[i].pm<=p[j].mem)
{
p[j].mem=i+1;
P a g e | 65 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
break;
}
}
}
printf("PROCESS MEMORY MEMORYPARTISION MEMORY ALLOCATION");
for(i=0;i<x;i++)
printf("\n %d
%d
%d ",p[i].pm,t[i],p[i].mem);
return 0;
}
OUTPUT:
ENTER NUMBER OF MEMORY PARTISION:
5
ENTER THE SIZE OF MEMORY PARTISION:
100
500
200
300
600
ENTER NUMBER OF PROCESS:
4
ENTER THE MEMORY SIZE FOR EACH PROCESS:
212
417
112
420
PROCESS MEMORY
212
417
112
420
0
MEMORYPARTISION
100
500
200
300
600
MEMORY ALLOCATION
100
1
3
300
2
RESULT:
The C program to implement first fit algorithm has been executed successfully and the output has
been verified.
DEPARTMENT OF CSE
DEPARTMENT OF CSE
for(i=0;i<n;i++)
{
for(j=0;j<x;j++)
{
if(p[i].pm<=p[j].mem)
{
p[j].mem=i+1;
break;
}
}}
printf("\n PROCESS MEMORY MEMORY PARTISION
MEMORY ALLOCATION");
for(i=0;i<x;i++)
printf("\n %d %d %d ",p[i].pm,a[i].mem,p[i].mem);
return 0;
}
OUTPUT:
ENTER NUMBER OF MEMORY PARTISION:
5
ENTER SIZE OF MEMORY PARTISION:
100
500
200
300
600
ENTER NUMBER OF PROCESS:
4
ENTER THE MEMORY SIZE FOR EACH PROCESS:
212
417
112
420
PROCESS MEMORY
212
417
112
420
0
MEMORY PARTISION
100
200
300
500
600
MEMORY ALLOCATION
100
3
1
2
4
RESULT:
The C program to implement best fit algorithm has been executed successfully and the
output has been verified.
DEPARTMENT OF CSE
DEPARTMENT OF CSE
{
if(p[i].pm<=p[j].mem)
{
p[j].mem=i+1;
break;
} }}
printf("\n PROCESS MEMORY MEMORY PARTISION
MEMORY ALLOCATION");
for(i=0;i<x;i++)
printf("\n %d
%d
%d ",p[i].pm,a[i].mem,p[i].mem);
return 0;
}
OUTPUT:
ENTER NUMBER OF MEMORY PARTISION
5
ENTER SIZE OF MEMORY PARTISION
100
500
200
300
600
ENTER NUMBER OF PROCESS
4
ENTER THE MEMORY SIZE FOR EACH PROCESS:
212
417
112
420
PROCESS MEMORY
212
417
112
420
0
MEMORY PARTISION
600
500
300
200
100
MEMORY ALLOCATION
1
2
3
200
100
RESULT:
The C program to implement worst fit algorithm has been executed successfully and the output has been
verified.
DEPARTMENT OF CSE
EX.NO.8
PAGE REPLACEMENT
DATE:
AIM :
To write a C program to implement the following page replacement algorithms
1)FIFO
2)LRU
3)OPTIMAL
FIFO PAGE REPLACEMENT ALGORITHM
ALGORITHM:
1: Read functions fifo outside main class
2: Inside main function
3: Read number of pages in reference string
4: Read number of frames
5: Read number of page faults if all the condition satisfies the following statements are displayed
6: replacement stratergies are efficient
7: fifo page replacement stratergy is efficient
8: End processing
PROGRAM
#include<stdio.h>
#include<conio.h>
int fr[100],n;
void main()
{
void display();
int i,j, page[100],p,pages;
int flag1=0,flag2=0,pf=0,top=0;
clrscr();
printf("\n Enter total number of frames :\n");
scanf("%d",&n);
printf("\n Enter the toal number of page reference string :\n");
scanf("%d",&pages);
for(i=0;i<n;i++)
{
fr[i]=-1;
}
printf("\nEnter the page reference string :");
for(i=0;i<pages;i++)
{
scanf("%d",&p);
page[i]=p;
}
for(j=0;j<pages;j++)
{
flag1=0;
flag2=0;
P a g e | 71 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
//
for(i=0;i<pages;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
j=0;
if(flag1==0)
{
for(i=0;i<n;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
pf++;
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=n)
top=0;
}
display();
}
printf("\n Number of page faults : %d ",pf);
getch();
}
void display()
{
int i;
printf("\n");
for(i=0;i<n;i++)
printf("%d\t",fr[i]);
}
OUTPUT
Enter total number of frames :
4
Enter the toal number of page reference string :
11
P a g e | 72 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
-1
2
2
2
2
2
2
5
5
5
5
-1
-1
3
3
3
3
3
3
1
1
1
-1
-1
-1
4
4
4
4
4
4
2
2
DEPARTMENT OF CSE
DEPARTMENT OF CSE
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
pf++;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<n;i++)
fs[i]=0;
for(k=j-1,l=1;l<=n-1;l++,k--)
{
for(i=0;i<n;i++)
{
if(fr[i]==page[k])
fs[i]=1;
}
}
for(i=0;i<n;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=page[j];
pf++;
}
display();
}
printf("\n no of page faults :%d",pf);
getch();
}
void display()
{
int i;
printf("\n");
for(i=0;i<n;i++)
printf("\t%d",fr[i]);
}
Enter total number of frames :
4
Enter the toal number of page reference string :
11
DEPARTMENT OF CSE
-1
2
2
2
2
2
2
2
2
2
2
-1
-1
3
3
3
3
6
6
6
6
3
-1
-1
-1
4
4
4
4
5
5
5
5
no of page faults :7
DEPARTMENT OF CSE
DEPARTMENT OF CSE
for(i=0;i<n;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
pf++;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<n;i++)
{ lg[i]=0;
}
for(i=0;i<n;i++)
{
for(k=j+1;k<pages;k++)
{
if(fr[i]==page[k])
{
lg[i]=k-j;
break;
}
}
}
found=0;
for(i=0;i<n;i++)
{
if(lg[i]==0)
{
index=i;
found=1;
break;
}
}
if(found==0)
{
max=lg[0];
index=0;
for(i=1;i<n;i++)
{
if(max<lg[i])
{
max=lg[i];
index=i;
}
}
}
fr[index]=page[j];
P a g e | 78 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
pf++;
}
display();
}
printf("\n no of page faults:%d",pf);
getch();
}
void display()
{
int i;
printf("\n");
for(i=0;i<n;i++)
printf("\t%d",fr[i]);
}
Enter total number of frames :
4
Enter the toal number of page reference string :
11
Enter the page reference string :1 2 3 4 2 1 6 5 1 2 3
1
1
1
1
1
1
1
1
1
1
1
-1
2
2
2
2
2
2
2
2
2
2
-1
-1
3
3
3
3
3
3
3
3
3
-1
-1
-1
4
4
4
6
5
5
5
5
no of page faults:6
RESULT:
Thus the C programs for page replacement algorithms are entered and verified.
DEPARTMENT OF CSE
EX.NO.9
DISK SCHEDULING
DATE:
AIM:
1.
2.
3.
4.
ALGORITHM:
1: read the number of cylinders
2: Enter the values of cylinders
3: read the starting head position
4: enter the starting head position
5:
enter the order of visiting the cylinder
6:
b+=abs(h-a[i]);
h=a[i];
7: finally calculate the seek time
8:end processing
PROGRAM:
#include<stdio.h>
//#include<conio.h>
#include<stdlib.h>
//#include<process.h>
int h,a[20],b=0,i,j,n;
main( )
{
// clrscr( );
printf("FIRST COME FIRST SERVE DISK SCHEDULING\n");
printf("\nEnter the Number of Requests : ");
scanf("%d",&n);
printf("\nEnter the requests : \n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\nEnter the Starting Head Position : ");
scanf("%d",&h);
printf("\nThe Order of Visiting the Cylinders:\n");
for(i=1;i<=n;i++)
printf("\t%d",a[i]);
for(i=1;i<=n;i++)
{
b+=abs(h-a[i]);
h=a[i];
}
printf("\nThe Seek Time is %d\n",b);
P a g e | 80 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
// getch( );
}
[staff@localhost diskpgm]$ cc -o p fcfs.c
[staff@localhost diskpgm]$ ./p
Output:
Enter the Number of Requests : 4
Enter the requests :
5
1
6
2
Enter the Starting Head Position : 4
The Order of Visiting the Cylinders:
5
1
6
2
The Seek Time is 14
DEPARTMENT OF CSE
SSTF
ALGORITHM:
1: read the number of cylinders
2: Enter the values of cylinders
3: read the starting head position
4: enter the starting head position
5:
enter the order of visiting the cylinder
6:
seek=seek+abs(hr-d[i]);
hr=d[i];
7: then calculate the seek time
8:
then declare the sstf function
9:
h=a[c];
d[z]=a[c];
z++;
a[c]=9999;
10:
return(0)
11:
end processing
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int sstf();
int seek=0,t1,t2,n,a[20]={{0}},z=1,d[20]={{0}},h=0;
void main()
{
int i,j,hr;
clrscr();
printf("\t\t SHORTEST SEEK TIME FIRST SCHEDULING \n\n");
printf("Enter the Number of requests : ");
scanf("%d",&n);
printf("\nEnter the requests : \n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\nEnter the Starting Head Position : ");
scanf("%d",&h);
hr=h;
printf("\nThe Order of Visiting the Cylinders : \n");
for(i=1;i<=n;i++)
sstf();
printf("\n");
for(i=1;i<=n;i++)
{
seek=seek+abs(hr-d[i]);
hr=d[i];
}
printf("\nThe Seek Time is %d",seek);
getch();
}
int sstf()
P a g e | 82 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
{
int b[20]={{0}},c=1,i,j;
for(i=1;i<=n;i++)
b[i]=abs(h-a[i]);
for(i=1;i<=n;i++)
if(b[c]>b[i])
c=i;
printf("\t%d",a[c]);
h=a[c];
d[z]=a[c];
z++;
a[c]=9999;
return(0);
}
OUTPUT:
Enter the Number of requests : 4
Enter the requests :
5
1
6
2
Enter the Starting Head Position : 4
The Order of Visiting the Cylinders :
5
6
2
1
The Seek Time is 7
DEPARTMENT OF CSE
SCAN
ALGORITHM:
1: read the ending position of the disc
2: Enter the number of cylinders
3: enter the starting head position
4: enter the order of visiting the cylinder
5:
right=right+abs(h-a[i]);
h=a[i];
6:
right=right+abs(h-end);
h=end;
7: finally calculate the seek time
8:
end processing
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,req[30],head,i,t,j,move,n,ch,g[30],c,h,cy,s[15];
clrscr();
printf("Disk Scheduling - SCAN");
printf("\nTotal number of cylinders: ");
scanf("%d",&cy);
printf("Enter the current head position: ");
scanf("%d",&head);
h=head;
printf("Enter the number of requests:");
scanf("%d",&n);
move=0;
printf("Enter the requests (1 to %d):\n",cy);
req:
for(i=0;i<n;i++)
{
scanf("%d",&req[i]);
s[i]=req[i];
if(req[i]>cy||req[i]<1)
{
printf("Enter requests only between 1-%d..",cy);
goto req;
}
}
printf("\nCurrent\tNext\tNo of Tracks traversed\n");
for(i=0;i<n;i++)
for(j=i;j<n;j++)
if(s[i]>s[j])
{
t=s[i];
P a g e | 84 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
s[i]=s[j];
s[j]=t;
}
for(i=0;i<n;i++)
if(s[i]>h)
break;
x=i;
for(c=0;i<n;i++)
{
printf("\n%d\t%d\t%d",head,s[i],abs(head-s[i]));
move+=abs(head-s[i]);
head=s[i];
g[c++]=s[i];
}
move+=abs(cy-head);
printf("\n%d\t%d\t%d",head,cy,abs(head-s[i]));
head=cy;
for(i=x-1;i>=0;i--)
{
printf("\n%d\t%d\t%d",head,s[i],abs(head-s[i]));
move+=abs(head-s[i]);
head=s[i];
g[c++]=s[i];
}
printf("\n\nOrder of servicing:%d ",h);
for(i=0;i<n;i++)
printf("%d ",g[i]);
printf("\n\nTotal Head Movements: %d",move);
getch();
}
OUTPUT:
Total number of cylinders: 7
Enter the current head position: 4
Enter the number of requests:4
Enter the requests (1 to 7):
5
1
6
2
Current Next
4
5
6
7
2
5
6
7
2
1
No of Tracks traversed
1
1
6
5
1
Order of servicing:4 5 6 2 1
Total Head Movements: 9
P a g e | 85 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
C-SCAN
ALGORITHM:
1: read the ending position of the disc
2: Enter the number of cylinders
3: enter the starting head position
4: enter the order of visiting the cylinder
5:
right=right+abs(h-a[i]);
h=a[i];
6:
right=right+abs(h-end);
h=end;
7: finally calculate the seek time
8:end processing
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,req[30],head,i,t,j,move,n,ch,g[30],c,h,cy,s[15];
clrscr();
printf("Disk Scheduling - CSCAN");
printf("\nTotal number of cylinders: ");
scanf("%d",&cy);
printf("Enter the current head position: ");
scanf("%d",&head);
h=head;
printf("Enter the number of requests:");
scanf("%d",&n);
move=0;
printf("Enter the requests (1 to %d):\n",cy);
req:
for(i=0;i<n;i++)
{
scanf("%d",&req[i]);
s[i]=req[i];
if(req[i]>cy||req[i]<1)
{
printf("Enter requests only between 1-%d..",cy);
goto req;
}
}
printf("\nCurrent\tNext\tNo of Tracks traversed\n");
for(i=0;i<n;i++)
for(j=i;j<n;j++)
if(s[i]>s[j])
{
t=s[i];
P a g e | 86 OPERATING SYSTEMS LABORATORY
DEPARTMENT OF CSE
s[i]=s[j];
s[j]=t;
}
for(i=0;i<n;i++)
if(s[i]>h)
break;
x=i;
for(c=0;i<n;i++)
{
printf("\n%d\t%d\t%d",head,s[i],abs(head-s[i]));
move+=abs(head-s[i]);
head=s[i];
g[c++]=s[i];
}
move+=abs(cy-head);
printf("\n%d\t%d\t%d",head,cy,cy-head);
move+=cy;
printf("\n%d\t%d\t%d",cy,0,cy);
head=0;
for(i=0;i<x;i++)
{
printf("\n%d\t%d\t%d",head,s[i],abs(head-s[i]));
move+=abs(head-s[i]);
head=s[i];
g[c++]=s[i];
}
printf("\n\nOrder of servicing:%d ",h);
for(i=0;i<n;i++)
printf("%d ",g[i]);
printf("\n\nTotal Head Movements: %d",move);
getch();
}
DEPARTMENT OF CSE
OUTPUT:
Total number of cylinders: 7
Enter the current head position: 4
Enter the number of requests:4
Enter the requests (1 to 7):
5
1
6
2
Current Next
4
5
6
7
0
1
5
6
7
0
1
2
No of Tracks traversed
1
1
1
7
1
1
Order of servicing:4 5 6 1 2
Total Head Movements: 12
RESULT:
Thus the various disk scheduling algorithm has been entered and verified.
DEPARTMENT OF CSE