Os Lab Record Cse
Os Lab Record Cse
RECORD BOOK
REGULATION-2021
NAME
REG.NO
CLASS / SEM
DEPARTMENTOFCOMPUTER SCIENCE AND ENGINEERING
NAME
REGNO
YEAR / CLASS / SEC IInd YEAR / CSE / B
BONAFIDE CERTIFICATE
REG.NO FOR
9 Implement Threading
paging Technique
10
VISION:
To emerge as a Premier Institute for developing industry ready Engineers with competency, initiative and
character to meet the challenges in global environment.
MISSION:
To impart state-of-the-art engineering and professional education through strongtheoretical basics and
hands on training to students in their choice of field.
To serve our students by teaching them leadership, entrepreneurship, teamwork,values, quality, ethics
and respect for others.
VISION
To produce the leaders in the field of Computer Science and Engineering, evolving as a Centre of
Excellence for Learning and Research.
MISSION
• To develop globally competent engineers capable of providing secure and Out-of-the Box computing
andcutting-edge technology solutions.
• To educate students with ethical values and to serve society with innovative, intelligent products
andservices.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PEO1: Graduates shall apply their technical competence in computer science to solve real world problems, with
technical and people leadership.
PEO2: Graduates shall have Conduct cutting edge research and develop solutions on problems of social
relevance.
PEO3: Graduates shall become leaders Work in a business environment, exhibiting team skills, work
ethics, adaptability and lifelong learning.
PSO 1 ; Student will be able to Exhibit design and programming skills to build and automate business
solutions using cutting edge technologies.
PSO 2 ; Student will be able to Strong theoretical foundation leading to excellence and excitement towards
research, to provide elegant solutions to complex problems.
PSO 3 ; Student will be able to Ability to work effectively with various engineering fields as a team to
design, build and develop system applications.
PROGRAM OUTCOMES(PO)
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 modeling 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
insocietal 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.
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. Lifelong learning: Recognize the need for, an have the preparation and ability to engage in
independentand life-long learning in the broadest context of technological change.
COURSE OBJECTIVES:
LIST OF EXPERIMENTS:
LABORATORY PLAN
SYLLABUS:
Ex No LIST OF EXPERIMENTS HOURS
3 Process Management using System Calls : Fork, Exit, Getpid, Wait, Close 3
Abraham Silberschatz, Peter Baer Galvin and Greg Gagne, “Operating System Concepts”,
T
10thEdition, John Wiley and Sons Inc., 2018.
T Andrew S Tanenbaum, "Modern Operating Systems", Pearson, 5th Edition, 2022 New Delhi
T Abraham Silberschatz, Peter Baer Galvin and Greg Gagne, “Operating System Concepts”, 9th
Edition, John Wiley and Sons Inc., 2012.
R D M Dhamdhere, “Operating Systems: A Concept-Based Approach”, Second Edition,
TataMcGraw-Hill Education, 2007.
COURSE PRE-REQUISITES:
COURSE OBJECTIVES:
COURSE OUTCOMES:
BLOOMS
PO(1..12) PSO(1,2,3)
S.NO TAXONOMY DESCRIPTION
LEVEL
MAPPING MAPPING
Remembring
C217.1 Define and implement UNIX Commands. PO1,PO3 PSO1, PSO3
(Level 1)
Analyzing Compare the performance of various CPU
C217.2 PO1,PO3,PO5 PSO1, PSO3
(level 4) Scheduling Algorithms.
Analyzing Compare and contrast various Memory
C217.3 PO3,PO6 PSO1, PSO3
(level 4) Allocation Methods.
Rememberin
Define File Organization and File
C217.4 g PO3,PO6 PSO1, PSO3
Allocation Strategies.
(Level 1)
Applying Implement various Disk Scheduling PO1, PO2,
C217.5 PSO1, PSO3
(Level 3) Algorithms. PO5
COURSE OVERALL PO/PSO MAPPING:
COURSE OUTCOMES VS POs MAPPING (DETAILED; HIGH: 3; MEDIUM: 2; LOW: 1):
PO PO PO PO PO PO PO PO PO PO PO PO PS PS PS
S.NO.
1 2 3 4 5 6 7 8 9 10 11 12 O1 O2 O3
C217.1 3 2 3 2 3 2 2 3 2 1
C217.2 3 2 3 2 3 2 2 3 3 2
C217.3 2 3 3 3 2 3 2 2 2 3
C217.4 2 3 3 2 3 3 2 2 3 2
C217.5 3 2 2 3 2 3 3 3 3 2
C217 2.5 3 3 2 3 2 3 2 2.5 2
* For Entire Course, PO & PSO Mapping
PO/PSO LEVEL OF
S.NO JUSTIFICATION
MAPPED MAPPING
Student will be able to Apply the knowledge of mathematics,
C217.1 PO1 H science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering
problems.
Student will be able to Identify, formulate, review research
C217.1 PO2 M literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Student will be able to Design solutions for complex
engineering problems and design system components or
C217.1 PO3 H processes that meet the specified needs with appropriate
consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
Student will be able to Use research-based knowledge and
C217.1 PO4 M research methods including design of experiments, analysis
and interpretation of data, and synthesis of the information to
provide valid conclusions.
Student will be able to Create, select, and apply appropriate
C217.1 PO5 H techniques, resources, and modern engineering and IT tools
including prediction and modeling to complex engineering
activities with an understanding of the limitations.
Student will be able to Function effectively as an individual,
C217.1 PO9 M and as a member or leader in diverse teams, and in
multidisciplinary settings.
Student will be able to Communicate effectively on complex
engineering activities with the engineering community and
C217.1 PO10 M 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.
Student will be able to Demonstrate knowledge and
understanding of the engineering and management principles
C217.1 PO11 H and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary
environments.
Student will be able to Exhibit design and programming
C217.1 PSO1 M skills to build and automate business solutions using cutting
edge technologies.
Student will be able to Ability to work effectively with
C217.1 PSO3 L various engineering fields as a team to design, build and
develop system applications.
Student will be able to Apply the knowledge of mathematics,
C217.2 PO1 H science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering
problems.
Student will be able to Identify, formulate, review research
C217.2 PO2 M literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Student will be able to Design solutions for complex
engineering problems and design system components or
C217.2 PO3 H processes that meet the specified needs with appropriate
consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
Student will be able to Use research-based knowledge and
C217.2 PO4 M research methods including design of experiments, analysis
and interpretation of data, and synthesis of the information to
provide valid conclusions.
Student will be able to Create, select, and apply appropriate
C217.2 PO5 H techniques, resources, and modern engineering and IT tools
including prediction and modeling to complex engineering
activities with an understanding of the limitations.
Student will be able to Function effectively as an individual,
C217.2 PO9 M and as a member or leader in diverse teams, and in
multidisciplinary settings.
Student will be able to Communicate effectively on complex
engineering activities with the engineering community and
C217.2 PO10 M 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
Student will be able to Demonstrate knowledge and
understanding of the engineering and management principles
C217.2 PO11 H and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary
environments.
Student will be able to Exhibit design and programming
C217.2 PSO1 M skills to build and automate business solutions using cutting
edge technologies.
Student will be able to Ability to work effectively with
C217.2 PSO3 L various engineering fields as a team to design, build and
develop system applications.
Student will be able to Apply the knowledge of mathematics,
C217.3 PO1 H science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering
problems.
Student will be able to Identify, formulate, review research
C217.3 PO2 M literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Student will be able to Design solutions for complex
engineering problems and design system components or
C217.3 PO3 H processes that meet the specified needs with appropriate
consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
Student will be able to Use research-based knowledge and
C217.3 PO4 M research methods including design of experiments, analysis
and interpretation of data, and synthesis of the information to
provide valid conclusions.
Student will be able to Create, select, and apply appropriate
C217.3 PO5 H techniques, resources, and modern engineering and IT tools
including prediction and modeling to complex engineering
activities with an understanding of the limitations.
Student will be able to Function effectively as an individual,
C217.3 PO9 M and as a member or leader in diverse teams, and in
multidisciplinary settings.
Student will be able to Communicate effectively on complex
engineering activities with the engineering community and
C217.3 PO10 M 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.
Student will be able to Demonstrate knowledge and
understanding of the engineering and management principles
C217.3 PO11 H and apply these to one’s own work, as a member and leader
in a team, to manage projects and in multidisciplinary
environments.
Student will be able to Exhibit design and programming
C217.3 PSO1 M skills to build and automate business solutions using cutting
edge technologies.
Student will be able to Ability to work effectively with
C217.3 PSO3 L various engineering fields as a team to design, build and
develop system applications.
Student will be able to Apply the knowledge of mathematics,
C217.4 PO1 H science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering
problems.
Student will be able to Identify, formulate, review research
C217.4 PO2 M literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Student will be able to Design solutions for complex
C217.4 PO3 H 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.
PROPOSED
S.NO. DESCRIPTION
ACTIONS
1 Linux commands and shell scripting ASSIGNMENT
1 Kernel Security
2 Kernel stack overflows elimination
1 http://www.brokenthorn.com/Resources/OSDev13.html
2 http://www.osnews.com/story/24405/Hobby_OS-deving_3_Designing_a_Kernel/
3 http://nptel.ac.in/courses/106106144/
4 http://nptel.ac.in/courses/106108101/
5 http://ww5.linuxdrivers.net/
DELIVERY/INSTRUCTIONAL METHODOLOGIES:
ASSESSMENT METHODOLOGIES-DIRECT
☐ TESTS/MODEL ☐ UNIV.
☐ ASSIGNMENTS ☐ STUD. SEMINARS
EXAMS EXAMINATION
ASSESSMENT METHODOLOGIES-INDIRECT
☐ ASSESSMENT OF COURSE OUTCOMES ☐ STUDENT FEEDBACK ON FACULTY
(BY FEEDBACK, ONCE) (TWICE)
Prepared by Approved by
ANUSHA P Dr. JUSTIN JOSE
(Assit. Prof) (HOD)
EXP No : 1
INSTALLATION OF WINDOWS OPERATING SYSTEM
DATE :
AIM
Make sure that you are using Usb Drive that is At least 4gb For The 32-Bit- Version and 8gb forthe 64-Bit
Version.
Rufus is one of several programs that allow you to create an “ISO image” on a USB drive. Tocreate a
bootable USB using Rufus, all we need is:
Important Notes
1. In order to perform a clean installation of Windows 10, you must own a valid Windows 10product
key to activate Windows.
2. If you bought a pre-installed Windows 10 computer (on which the OS was pre-installed fromthe
computer manufacturer), then the product key is stored in BIOS and it will be retrieved automatically (from
BIOS) during Windows installation.
3. If you’re currently running Windows 8.1 or Windows 7 SP1 (already activated), and you wantto
upgrade your computer to Windows 10 select “Upgrade this PC now” at the next screen & then follow the
onscreen instruction to upgrade your OS to Windows 10.
STEP 4: Choose the Windows 10 Edition that you want to download and click Next.Important Notes
1. If you want to install Windows 10 on the current PC, leave the Use the recommendedoptions for this PC
box checked. At this case the Media Creation Tool will create a Windows 10 installation disk with the same
language, edition, and architecture as thecurrent PC.
STEP 7: Choose the destination location (where the ISO file will be saved/stored) & press Save.
1. Click Open DVD burner and place a blank DVD disk on the DVRW tray in order to createimmediately a
bootable Windows 10 DVD installation/repair disk, or
2. Click Finish.
EXP No : 2a
BASICS OF UNIX COMMANDS
DATE :
AIM:
COMMAND:
1. Date Command:
Syntax:
P = Display AM or PM
S = Seconds
Z = Time zone
Syntax:
$date “+%H-%M-%S”
2. Calender Command:
This command is used to display the calendar of the year or the particular month of calendaryear.
a. $cal <year>
b. $cal <month><year>
Here the first syntax gives the entire calendar for given year & the second Syntax gives thecalendar of
reserved month of that year.
3. Echo Command:
To have the output in the same line, the following commands can be used
Syntax Secho
<text>text
To have the output in different line, the following command can be used.
>line2
>line3?
4. ‘who’ Command:
It is used to display who are the users connected to our computer currently.
Syntax: $who-option’s
Options:-
b-Display the last booting date or time or when the system was lastely rebooted.
5. ‘who am i’ Command:
Display the details of the current working directory.
Syntax: $who am i
6. ‘tty’ Command:
It will display the terminal name.
Syntax:$tty
$bc operations
^d
$
1 base- inputbase
Base:
8. ‘CLEAR’ Command:
It is used to clear the screen.
Syntax: Sclear
9. ‘MAN’ Command:
It helps us to know about the particular command and its options & working. It is like “help”command in
windows.
If the command does not contain any argument means it is working in the Currentdirectory.
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.
DIRECTORY RELATED COMMANDS:
Syntax: $pwd
2. MKDIR Command:
To create or make a new directory in a current directory.
3. CD Command:
To change or move the directory to the mentioned directory.
4. RMDIR Command:
To remove a directory in the current directory & not the current directory itself.
1. CREATE A FILE:
2. DISPLAY A FILE:
To display the content of file mentioned we use CAT command without “>” operator.
Syntax:$cat 18ilename
3. COPYING CONTENTS:
To copy the content of one file with another. If file doesnot exist, a new file is created and if thefile exists
with some data then it is overwritten.
Options:-
Syntax:
$cat ?n <filename>
4. SORTING A FILE:
To sort the contents in alphabetical order in reverse order.
Syntax:
$sort<filename>
Syntax:
6. MOVE Command:
To completely move the contents from source file to destination file and to remove the sourcefile.
Syntax:
7. REMOVE Command:
To permanently remove the file we use this command.
Syntax:
$em <filename>
8. WORD Command:
To list the content count of no of lines, words, characters.\
Synatx:
$uc <filename>
9. LINE PRINTER:
To print the line through the printer, we use Ip command.
$lp <filename>
Syntax:
$pg <filename>
11. FILTERS AND PIPES:
HEAD: It is used to display the top ten lines of file.
Syntax: $head-<filename>
TAIL: This command is used to display the last ten lines of file.
Syntax: $tail<filename>
PAGE: This command shows the page by page a screen full of information is displayed her which the page
command displays a prompt and passes for the user to strike the enter key tocontinue scrolling.
MORE: It also displays the file page by page. To continue scrolling with more command, pressthe space
bar key.
Syntax: $more<filename>
GREP: This command is used to search and print the specified patterns from the file.
SORT: This command is used to sort the data in some order.Syntax: $sort<filename>
PIPE: It is a mechanism by which the output of one command can be channeled into the inputof another
command.
Syntax: $who | we –l
TR: The tr filter is used to translate one set of characters from the standard inputs to another.Syntax: $tr “[a-
z]”“[A-Z]”
1. Commmand:MESG
Description: The message command is used to give permission to other users send message toyour terminal.
Syntax: $mesg y
2. Command: WRITE
Description: This command is used to communicate with other users, who are logged in at thetime.
5. Command: REPLY
Description: It is used to send reply to specified user.
Result:
Thus the basic unix commands has been studied and executed successfully.
EXP No : 2b(i)
SHELL PROGRAMMING - CONCATENATION OF TWO STRINGS
DATE :
AIM:
ALGORITHM:
Step2 : To concatenate the two strings and store the result in a new variable,
Step 4:Stop.
PROGRAM:
read str1
read str2
OUTPUT:
AIM:
ALGORITHM:
Step 3: else
Step 4: Stop
PROGRAM:
read strl
read str2
if [ $strl = $str2]
then
else
fi
OUTPUT:
SAMPLE 1:
SAMPLE 2:
AIM:
ALGORITHM:
Step 1: Prompt the user to enter a values for A ,B,C using the `echo`
command.
Step 2:Read the values of A,B ,C using the `read` command and store it in the
variable`a`,’b’,’c’.
Step 3.1: If A is greater than both B and C, output "A is greater" using the `
echo` command.
Step 3.2:Else if B is greater than both A and C, output "B is greater" using
Step 3.3: Else, output "C is greater" using the `echo` command.
Step 4:Stop.
PROGRAM:
read a
read b
read c
then
then
else
fi
OUTPUT:
Enter A:23
Enter B:45
Enter C:67
C is greater
EXP No : 2b(iv)
SHELL PROGRAMMING - FIBONACCI SERIES
DATE :
AIM:
ALGORITHM:
Step 1:Start.
Step 6.3:b=show
Step 7:End
PROGRAM:
read n
a=-1
b=1
i=0
while [ $i ?le $n ]
do
t=’expr $a +$b’
echo $t
a=$b
b=$t
i=’expr $i + 1
done
OUTPUT:
0
1
1
2
3
5
EXP No : 2b(v)
SHELL PROGRAMMING - ARITHMETIC OPERATIONS
USING CASE
DATE :
AIM:
ALGORITHM:
Step 1: Start
Step 6: Stop
PROGRAM:
echo “ 1.Addition”
echo “2.Subraction”
echo “ 3.Multiplication”
echo “ 4.Division”
read a
read b
read c
echo” b is $b c is $c
”case $a in
::
2) d='expr $b -$c
echo” the difference is $d”
::
3) d='expr $b \ $c
echo “the product is $d”
::
4) d='expr $b / $c
echo “the quotient is $d”
::
esac
OUTPUT:
1.Addition
2.Subraction
3.Multiplication
4.Division
b is 3 c is 4
the sum is 7
RESULT:
Thus the given shell programs are implemented and output is verified successfully.
EXP No : 3(a)
PROCESS MANAGEMENT USING SYSTEM CALLS: FORK
DATE :
AIM:
FORK:
ALGORITHM:
Step 5: Otherwise
Print "Parent process"
Step 6: Stop
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include<sys/types.h>
pid_t pid:
pid = fork();
if (pid==0)
exit(0);
else
exit(EXIT_FAILURE);
return 0;
}
OUTPUT:
AIM:
ALGORITHM:
Step 1:Define the main function with an integer return type and two arguments: argc` and
`argv`.
Step 2:Declare a variable `pid` of type `pid_t` to store the process ID returned by the fork()system call.
Step 3:Call the `fork()` system call to create a new process. The return value of `fork()` will be0 in the child
process and a positive integer (the child's PID) in the parent process. If `fork()` returns a negative value,
print an error message and exit the program with a failure status.
Step 3.1:If `pid` is equal to 0, the code inside the `if` block will be executed in the child process.Print a
message indicating that it is the child process and print its process ID using `getpid()`.
Step 5:Exit the child process with a status of 0 using the `exit()` function. If `pid` is greater than0, the code
inside the `else if block will be executed in the parent process. Print a message indicating that it is the
parent process and print its process ID using `getpid()`.
Step 6:Declare a variable `status` of type `int` to store the exit status of the child process.
Step 7:Call the `wait()` system call to wait for the child process to terminate and store its exitstatus in
`status`.
Step 8:Print a message indicating that the child process has been reaped.
Step 9:If `fork()` returns a negative value, print an error message and exit the program with afailure status.
#include<stdio.h> // printf()
#include<stdlib.h> // exit()
#include<sys/types.h> // pid_t
#include<sys/wait.h> // wait()
{pid_t pid
; pid = fork():
if(pid==0)
int i;
for(i=0;i<8;i++)
{ printf("%d\n",i);
) exit(0);
int status;
wait(&status);
printf("Child is reaped\n");
}
else
{printf("Error in forking..\n")
;exit(EXIT_FAILURE);
}
return 0;
}
OUTPUT:
Child is reaped
EXP No : 3(c)
GETPID SYSTEM CALL
DATE :
AIM:
ALGORITHM:
Step 3:If the return value of `fork()` is less than 0, print an error message indicating that theprocess ID
could not be obtained and exit the program with a status of 1.
Step 4:If the return value of `fork()` is greater than or equal to 0, continue to the next step.
Step 5:In the parent process, call the `getpid()` system call to obtain the process ID and store itin an integer
variable `pid_t`.
Step 8:Call the 'sleep() function for 1 second to delay the execution of the program.
#include <stdio.h>
#include <sys/types.h>
int main(void)
if((fork())<0)
exit(1);
else
printf("Process id is %d\n",pid_1):
sleep(1);
exit(0);
}
return 0;
}
EXP No : 3(d)
EXIT SYSTEM CALL
DATE :
AIM:
ALGORITHM:
Step 2:Prompt the user to enter the last number and read the input using `scanf`.
Step 4:Inside the loop, use an `if` statement to check if the value of `` is equalto 6.
Step 5:If the condition is true, terminate the program using the `exit()` function with anargument of 0 to
indicate successful termination.
Step 6:If the condition is false, print the value of `i using `printf`.
Step 8:Add another `exit(0)` statement after the return statement to ensure thatthe program always
#include <stdio.h>
#include <stdlib.h>i
nt main()
int i, num;
scanf("%d", &num);
if (i == 6)
/*use exit () statement with passing 0 argument to show termination of the program without anyerror
message. */
exit(0):
else
return 0;
}
OUTPUT:
It is obtained.
AIM:
ALGORITHM:
Step 1:Declare a variable `filedesc` of type `size_t` to store the file descriptor returned by the
`open system call.
Step 2:Call the `open` system call with the filename "testfile.txt" and the flags `0_WRONLY`(to open the
file for writing only) and `0_CREAT` (to create the file if it does not exist).
Step 3: Check if the return value of `open` is less than 0. If it is, return 1 to indicate failure. Callthe `close`
system call with the file descriptor returned by `open`.
Step 4:Check if the return value of `close` is less than 0. If it is, return 1 to indicate failure.
#include <stdlib.h>
#include <fcntl.h>
int main(){
if(filedesc < 0)
return 1;
if(close(filedesc) < 0)
return 1;
return 0;
}
OUTPUT:
RESULT:
Thus the program process management using system calls: fork, exit, getpid wait ,closehas been
implemented and output is verified successfully.
EXP No : 4(a)
IMPLEMENTATION OF FCFS SCHEDULING
DATE :
AIM:
ALGORITHM:
Step 2:Take input for the number of processes (n), burst times (b), and arrival times(a).
Write a regular expression for an identifier and number.Calculate the waiting time (w) for eachprocess by
subtracting the arrival time from the completion time.
Step 5:Calculate the turnaround time (t) for each process by subtracting the arrival time fromthe completion
time.
Step 6:Calculate the average waiting time (awt) and average turnaround time (att) by summingup the
respective values for all processes and dividing by the
Step 8:Print the waiting time and turnaround time for each process and the average waiting timeand
#include<stdio.h>
main()
int n,a[10].b[10],t[10],w[10].g[10].i.m;
floatatt=0,awt=0;
for(i=0;i<10;i++)
{
scanf("%d", &n):
printf("enter the burst times");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("\nenter the arrival times");
for(i=0;i<n;i++)
scanf("%d",&a[i]):
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i]:
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i]:
[i]=g[i+1]-a[i]:
awt=awi+w[i];
att=att+1/i];
}
awt #awt/n;
att=att/n;
printf("process waiting time\turnaround time\n");
for(i=0;i<n;i++)
{
printf("\tp%d\\%d %d\n",i,w[i],t[i]);
printf("the average waiting time is %fn",awt);
printf("the average turn around time is %n",att);
}
OUTPUT:
4983
0243
Process Waiting time Turn around time
0 0 4
p1 2 11
p2 9 17
p3 18 21
RESULT:
Thus the program FCFS scheduling is implemented and output is verified successfully.
EXP No : 4(b)
IMPLEMENTATION OF SJF SCHEDULING
DATE :
AIM:
ALGORITHM:
If two process have same btime,then FCFS is used to resolve the tie.
Step 6: Compute average wtime and ttime for each process as:wtimei+1=wtimei+btimei
ttimei=wtimei+btimei
Step 7: Compute average waiting time awat and average turn around tine atur.
Step 11:Stop.
PROGRAM:
#include<stdio.h>
int main()
int nj,temp,templ,temp2,pr[10],[10],[10],[10],p[10],I;
float att=0,awt=0;
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
scanf("%d",&n);
printf("enter the burst times");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
p[i]=i;
for(i=0;i<n;i++)
for(j=i;j<n;j++)
if(b[i]>b[j])
{
temp=b[i];
templ=p[i];
p[i]=p[j];
b[j]=temp;
p[j]=templ;
}
w[0]=0;
for(i=0;i<n;i++)
w[i+1]=w[i]+b[i];
for(i=0;i<n;i++)
t[i]=w[i]+b[i];
awt=awt+w[i];
att=att+t[i];
}
awt=awt/n;
att=att/n;
printf("\t process \t waiting time \ t turn around time \n");
for(i=0;i<n;i++)
printf("\t p[%d] \t%d \t\t %d\n",p[i],w[i],t[i]);
printf("the average waitingtime is %f",awt);
printf("the average turn around time is %f\n",att);
return 1;
}
OUTPUT:
24568
p[0] 0 2
p[1] 2 6
p[2] 6 11
p[3] 11 17
p[4] 17 25
RESULT:
Thus the program sjf scheduling has been implemented and output is verifiedsuccessfully.
EXP No : 4(c)
IMPLEMENTATION OF PRIORITY SCHEDULING
DATE :
AIM:
To implement the priority scheduling using c programming.
ALGORITHM:
Step 1:Define an array of structure process with members pid, btime, pri, wtime & time,
Step 2: Get length of the ready queue, i.e., number of process (say n)
a. If two process have same pri, then FCFS is used to resolve the tie.
Step 7: Compute average waiting time away and average turn around time atur
Step 8: Display the brime, pri, time and wtime for each process.
#include<stdio.h>
int main()
scanf("%d", &n);
for(i=0;i<n;i++)
printf(“\nP[%d]\n”,i+1);
printf("Burst Time:");
scanf(“%d”,&bt[i]);
printf "Priority:")
scanf("%d",&pr[i]);
//sorting burst time, priority and process number in ascending order using selection sort
for(i=0;i<n;i++)
pos=i;
for(j=i+1:j<n;j++)
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
wt[0]=0; //waiting time for first process is zero
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n;
total=0;
//average waiting time
for(i=0;i<n;i++)
return 0;
}
OUTPUT:
P[1]
Burst Time:6
Priority:3
P[2]
Burst Time:2
Priority:2
P[3]
Burst Time:14
Priority: 1
P[4]
Burst Time:6
Priority:4
p[3] 14 0 14
p[2] 2 14 16
p[3] 6 16 22
p[4] 6 22 28
Thus the program priority scheduling has been implemented and output is verifiedsuccessfully.
EXP No : 4(d)
IMPLEMENTATION OF ROUND ROBIN SCHEDULING
DATE :
AIM:
ALGORITHM:
Step 1: Get length of the ready queue, i.e., number of process (say n) .
Step 6: If Bi> TS then process takes more than one round. Therefore turnaround and waitingtime should
include the time spent for other remaining processes in the same round.
Step 9 : Display the burst time, turnaround time and wait time for each process (in order ofrounds they were
processed).
Step11: Stop
PROGRAM:
#include<stdio.h>
int main(){
int count,j,n,time,remain,flag=0,time quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Arrival Time and Burst Time for Process Process Numbered %d:"count+1);
scanf("%d",&at[count]);
scanf("%d", &bt[count]);
rt[count]=bt[count];
}
scanf("%d", &time_quantum);
printf("\n\nProcess\r| TurnaroundTime| Waiting Time\n\n");
for(time=0,count=0; remain!=0;)
{
if(rt[count]<=time_quantum&&rt[count]>0)
{
time+=rt[count]:
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
rt[count]-time quantum;
time+time quantum;
}
if(rt[count]==0 && flag==1)
remain--;
wait_time+=time-at[count]-bt[count];
turnaround_ time+=time-at[count];
flag=0;
if(count ==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
return 0;
OUTPUT:
Enter Arrival Time and Burst Time for Process Process Number 1:0
Enter Arrival Time and Burst Time for Process Process Number 2:1
Enter Arrival Time and Burst Time for Process Process Number 3:2
Enter Arrival Time and Burst Time for Process Process Number 4 :3
P[2] 9 4
P[3] 11 8
P[4] 14 10
P[1] 21 12
RESULT:
Thus the program round robin schedling has been impelemented and output is verified
successfully.
EXP No : 5
INTER PROCESS COMMUNICATION USING SHARED
MEMORY
DATE :
AIM:
ALGORITHM:
Step 3:shmat(): Before you can use a shared memory segment, you have to attach yourself
to it using shmat(). void *shmat(int shmid ,void *shmaddr ,int shmflg);
shmid is shared memory id. shmaddr specifies specific address to use but we should set
it to zero and OS will automatically choose the address
Step 4: shmdt(): When you’re done with the shared memory segment, your program should
detach itself from it using shmdt(). int shmdt(void *shmaddr);
Step 5: shmctl(): when you detach from shared memory,it is not destroyed. So, to destroy
shmctl() is used. shmctl(int shmid,IPC_RMID,NULL);
PROGRAM:
#include<stdio.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<sys/ipc.h>
int main(){
char *shmptr;
child=fork();
if(!child)
shmid=shmget(2041,32,IPC_CREAT|0666);
shmptr=shmat(shmid,0,0);
for(i=0;i<10;i++)
shmptr[i]='a'+i; putchar(shmptr[i]);
}
printf("\n\n %s", shmptr);
wait(NULL);
else
shmid=shmget(2041,32,0666);
shmptr=shmat(shmid,0,0);
for(i=0;i<10;i++)
putchar(shmptr[i]);
shmdt(NULL);
shmctl(shmid,IPC_RMID,NULL);
}
return 0;
}
OUTPUT:
Parent writing
abcdefghij
Child is reading
abcdefghij
RESULT:
Thus the program inter process communication using shared memory and output isverified
successfully.
EXP No : 6
MUTUAL EXCLUSION BY SEMAPHORE
DATE :
AIM:
ALGORITHM:
Step 1: 2 threads are being created, one 2 seconds after the first one.
Step 2: But the first thread will sleep for 4 seconds after acquiring the lock.
Step 3: Thus the second thread will not enter immediately after it is called, it will enter 4 – 2 = 2secs after
it is called.
Step 4: Stop.
PROGRAM:
#include <stdio.h>
int mutex=1,full=0,empty=3,x=0;
int main(){
int n
void producer();
void consumer();
int wait(int);
int signal(int);
printf(“\nl.Producern2.Consumer\n3.Exit”);
while(1)
{
printf("\nEnter your choice:");
scanf("%d",&n);
switch(n)
{
case 1: if((mutex==1)&&(empty!=0))
producer();
else
printf("Buffer is full!!"):
break;
case 2: if(mutex==1)&&(full!=0))
consumer();
else
printf("Buffer is empty!!");
break;
case 3:exit(0);
break;
}
return 0;
int wait(int s)
return (--s);
int signal(ints)
{
return(++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("nProducer produces the item %d",x);
mutex=signal(mutex);
}
void consumer()
mutex=wait(mutex):
full=wait(full);
empty=signal(empty);
}
OUTPUT:
1.Producer
2.Consumer
3.Exit
RESULT:
Thus the program mutual exclusion by semaphore is implemented and output is verified
successfully.
EXP No : 7
BANKERS ALGORITHM FOR DEAD LOCK AVOIDANCE
DATE :
AIM:
ALGORITHM:
Step 9. Stop.
PROGRAM:
#include<stdio.h>
void main(){
int r[1][10],av[1][10];
int all[10][10],max[10][10],ne[10][10],w[10],safe[10];
int i=0,j=0,k=0,l=0,np=0,nr=0,count=0,cnt=0;
scanf("%d",&np);
scanf("%d",&nr);
for(i=1;i<=nr;i++)
{
scanf("%d",&r[0][i]);
av[0][i]=r[0][i];
for(j=1;j<=nr;j++) all[i][j]=ne[i][j]=max[i][j]=w[i]=0;
for(i=1;i<=np;i++)
{
printf("\n");
for(j=1;j<=nr;j++)
{
scanf("%d",&all[i][j]);
av[0][j]=av[0][j]-all[i][j];
scanf("%d",&max[i][j]);
}
}
for(i=1;i<=np;i++)
for(j=1;j<=nr;j++)
ne[i][j]=max[i][j]-all[i][j];
for(i=1;i<=np;i++)
printf("pocess P%d",i);
for(j=1;j<=nr;j++)
{
printf("maximum d",max[i][j]);
printf("need %d",ne[i][j]);
printf("\n _ \n”);
printf("\nAvailability");
for(i=1;i<=nr;i++)
printf("R%d %d\t",i,av[0][i]);
printf("\n _ \n”);
printf("\n safe sequence");
for (count=1:count<=np:count++)
for(j=1;j<=nr:j++)
{
cnt=0;
for(j=1;j<=nr:j++)
cnt++;
if(cnt==nr)
k++;
safe[k]=i;
for(l=1;1<=nr;1++)
av[0][1]=av[0][1]+all[i][l];
printf("n P%d ",safe[k]);
printf("\n Availability");
for(l=1;1<=nr;I++)
printf("R%d %d",lav[0][1]);
w[i]=1;
}
getch();
}
OUTPUT:
321
112
412
444
345
524
pocess P1
allocated 3
maximum 4
need 1
allocated 2
maximum 4
need 2
allocated 1
maximum 4
need 3
RESULT:
Thus the program bankers algorithm has been implemented and output is verifiedsuccessfully.
EXP No : 8
DEADLOCK DETECTION ALGORITHM
DATE :
AIM:
ALGORITHM:
Step1:Mark each process that has a row in the Allocation matrix of all zeros.
Step 3:Find an index i such that process i is currently unmarked and the i th row of Qis less thanor equal to
W. That is, Q ik... Wk, for 1 ... k... m. If no such row is found, terminate the algorithm.
Step 4: If such a row is found, mark processi and add the corresponding row of the allocationmatrix to W.
That is, set Wk = Wk + Aik, for 1 ... k... m. Return to step 3.
PROGRAM:
#include<stdio.h>
int i,j,np.nr;
int main()
scanf("%d", &nr);
for(i=0;i<nr;i++){
printf("Total Amount of the Resource R%d: ",i+1);
scanf("%d", &r[i]);
}
for(i=0;i<np;i++)
for(j=0;j<nrp;j++)
scanf("%d",&request[i][j]);
printf("Enter the allocation matrix:");
for(i=0;i<n;i++)
for(j=0;j<nr;j++)
scanf("%d",&alloc[i][j]);
/*Available Resource calculation*/
for(j=0;j<nr;j++)
{
avail[j]=r[j];
for(i=0;i<np:i++)
{
avail[j]-=alloc[i][j];
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
if alloc[i][j]==0)
count++;
else break;
}
if(count==nr)
mark[i]=1;
// initialize W with avail
for(j=0;j<nr;j++)
w[j]=avail[j];
//mark processes with request less than or equal to W
for(i=0;i<n;i++)
int canbeprocessed=0;
if(mark[i]!=1)
{
for(j=0;j<nr:j++)
if request[i][j]<=w[j])canbeprocessed=1;
else
canbeprocessed=0;
break;
}
if(canbeprocessed)
{
mark[i]=1;
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
}
//checking for unmarked processes
int deadlock=0;
for(i=0;i<np;i++)
if(mark[i]!=1)
deadlock=1;
if(deadlock)
printf("n Deadlock detected");
else
}
OUTPUT:
01001
00101
00001
10101
00010
00000
Deadlock detected
RESULT:
Thus the program deadlock detection algorithm has been implemented and output isverified
successfully.
EXP No : 9
IMPLEMENT THREADING
DATE :
AIM:
ALGORITHM:
Step 3: Even if thread 2 is scheduled to start while thread was not done,access to shared
Step 5:Stop.
PROGRAM:
Thread creation
#include <unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
sleep(1);
printf("welcome!\n");
return NULL;
int main()
pthread_t tid;
printf("before thread");
pthread_create(&tid.NULL.mythread.NULL);
pthread_join(tid.NULL);
exit(0);
}
OUTPUT:
To Compile
cc filename.c -1 pthread
To Run
./a.out
RESULT:
Thus the program threading has been implemented and output is verified successfully.
EXP No : 10
PAGING TECHNIQUE
DATE :
AIM:
ALGORITHM:
Step1: Start.
Step 3: Compare no. of pages available and display it.Step 4: Determine the corresponding page.
#include<stdio.h>
int main()
clrscr();
scanf("%d",&ms);
scanf("%d",&ps);
nop = ms/ps;
printf("\nThe no. of pages available in memory are %d ",nop):
scanf("%d",&np);
rempages= nop;
for(i=1;i<=np;i++)
scanf(“%d”,&s[i]);
if(s[i] >rempages)
printf("\nMemory is Full");
break;
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
printf("Enter Logical Address to find Physical Address -- ");
else
{
pa=fno[x][y]*ps+offset;
}
OUTPUT:
Memory is Full
RESULT:
` Thus the program paging technique has been implemented and output is verifiedsuccessfully.
EXP No : 11(a)
MEMORY MANAGEMENT SCHEMES FIRST FIT
DATE :
AIM:
ALGORITHM:
Step 1:Declare structures hole and process to hold information about set of holes andprocesses
respectively.
Step 7: Print the list of process and their allocated holes or unallocated status.
Step 8: Print the list of holes, their actual and current availability.
Step 9: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max]f[max],i,j,nb,nf,temp,highest=0;
clrscr();
scanf("%d",&nf);
for(i=1;i<=nb;i++){
printf ("Block%d:",i);
scanf("%d",&b[i]);
for(i=i;i<=nf;i++)
{
scanf("%d",&f[i]);
for(i=1;i<=nf;i++)
for(j=1;j<=nb;j++)
{
if(temp>=0)
if( highest<temp)
ff[i]=j:
highest=temp;
frag[i]=highest:
bf[ff[i]]=1;
highest=0;
printf("\nFile_no:\File_size \Block_no:\Block_size:\Fragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\\%d",i,f[i],ff[i],b[ff[i]].frag[i]);
getch();
}
OUTPUT:
Block 1: 5
Block 2: 2
Block 3: 7
Enter the size of the files:-
File 1:1
File 2:4
1 1 3 7 6
2 4 1 5 1
RESULT:
Thus the program memory management schemes first fit has been implemented andoutput is
verified successfully.
EXP No : 11(b)
MEMORY MANAGEMENT SCHEMES BEST FIT
DATE :
AIM:
ALGORITHM:
Step 1: Declare structures hole and process to hold information about set of holes and processes
respectively.
Step 8: Print the list of holes, their actual and current availability.
Step 9: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max]f[max],i,j,nb,nf,temp,lowest=10000;
clrscr();
scanf "%d",&nb);
for(i=1;i<=nb;i++)
scanf "%d",&b[i]);
for(i=1;i<=nf;i++)
{
scanf(“%d”,&f[i]);
for(j=1;j<=nb;j++)
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
frag[i]=lowerst;
bf[ff[i]]=1;
lowest=10000;
}
for(i=1;i<=nf &&ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,ƒ[i],ff[i],b[ff[i]],frag[i]);
getch();
}
OUTPUT:
Block 1: 5
Block 2: 2
Block 3: 7
File 1:1
File 2:4
1 1 2 2 1
2 4 1 5 1
RESULT:
Thus the program memory management schemes best fit has been implemented andoutput is
verified successfully.
EXP No : 11(c)
MEMORY MANAGEMENT SCHEMES WORST FIT
DATE :
AIM:
ALGORITM:
Step 1: Declare structures hole and process to hold information about set of holes and processes
respectively.
Step 7: Print the list of process and their allocated holes or unallocated status.
Step 8: Print the list of holes, their actual and current availability.
Step 9: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
int frag[max],b[max]f[max],i,j,nb,nf,temp,lowest=10000;
scanf "%d",&nb);
for(i=1;i<=nb;i++)
scanf "%d",&b[i]);
for(i=1;i<=nf;i++)
scanf(“%d”,&f[i]);
for(j=1;j<=nb;j++)
if(bf[j]!=1)
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=l;
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,ƒ[i],ff[i],b[ff[i]],frag[i]);
getch( );
}
OUTPUT:
Block 1: 5
Block 2: 2
Block 3: 7
1 1 1 5 4
2 4 3 7 3
RESULT:
Thus the program memory management schemes worst has been implemented and isverified
successfully.
EXP No : 12(a)
FIFO PAGE REPLACEMENT ALGORITHM
DATE :
AIM:
ALGORITHM:
Step 1 : Start.
Step 10 : Stop.
PROGRAM:
#include<stdio.h>
#include<conio.h> i
nti,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
{
clrscr();
scanf(“%d”,&nof);
printf(“\n enter number of reference string..\n”);
scanf(“%d”,&nor);
printf(“\n enter the reference string..”);
for(i=0;i<nor;i++)
scanf(“%d”,&ref[i]);
printf(“\n the given reference string:”);
for(i+0;i<nor;i++)
printf(“%4d”,ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf(“\n”); for(i=0;i<nor;i++)
{
flag=0;
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
flag=1;
break;
}
}
if(flag==0)
{
pf++;
victim++;
victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf(“%4d”,frm[j]);
}
getch();
}
OUTPUT:
……………………………
5 6 4 1 2 3
Reference np5-> 5 -1 -1 -1
Reference np6-> 5 6 -1 -1
Reference np4-> 5 6 4 -1
Reference np1-> 5 6 4 1
Reference np2-> 2 6 4 1
Reference np3-> 2 3 4 1
RESULT:
Thus the program FIFO page replacement algorithm has been implemented and output isverified
successfully.
EXP No : 12(b)
LRU PAGE REPLACEMENT ALGORITHM
DATE :
AIM:
ALGORITHM:
Step 7: For each page in reference string in the given order, examine:
Step 9: Stop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
clrscr();
scanf("%d",&nof);
scanf("%d",&nor);
for(i=0;i<nor;i++)
scanf("%d",&ref[i]):
printf("n............................................................ ”);
for(i=0;i<nor;i++)
printf("%4d".reflil);
for(i=1;i<=nof;i++)
frm[i]=-1;
Irucal[i]=0;
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for( i=0;i<nor;i++)
flag=0;
for(j=0;j<nof;j++)
if(frm[j]==ref[i])
flag=1;
break;
if flag==0)
count++;
if(count<=nof)
victim++;
else victim=lruvictim();
pf++;
frm/victim]=ref[i];
for(j=0;j<nof:j++)
printf("%4d" frm[j]);
recent[ref[i]]=i;
getch();
}
int lruvictim()
int i,j,templ,temp2;
for(i=0;i<nof;i++)
templ=frm[i]:
lrucal[i]=recent[templ];
temp2=lrucal[0];
for(j=1;j<nof;j++)
if(temp2>lrucal[j])
temp2=lrucal[j];
for(i=0;i<nef;i++)
if (ref[temp2]==frm[i])
return i;
return 0;
}
OUTPUT:
……………………6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference 6 5 -
NO 5-> 1
Reference 6 5 4
NO 4->
Reference 2 5 4
NO 2->
Reference 2 3 4
NO 3->
Reference 2 3 1
NO 1->
No.of page
faults...6
RESULT:
Thus the program LRU page replacement algorithm has been implemented and output isverified
successfully.
EXP No : 12(c)
OPTIMAL (LFU) PAGE REPLACEMENT ALGORITHM
DATE :
AIM:
ALGORITHM:
1. Step 1: Get length of the reference string, say len.
2. Step 2:Get reference string and store it in an array, say rs.
3. Step 3: Get number of frames, say nf.
4. Step 4: Create access array to store counter that indicates a measure of recent usage.
5. Step 5: Create a function arrmin that returns position of minimum of the given array.
6. Step 6: Initalize frame array upto length nf to -1.
7. Step 7:Initialize position of the page replacement, say / to 0.
8. Step 8: Initialize freq to 0 to track page frequency
9. Step 9: Initialize no. of page faults, say count to 0.
10. Step 10: For each page in reference string in the given order, examine:
a. Check whether page exist in the frame array.
b. If page exist in memory then
i. Store incremented freq for that page position in access array.
c. If page does not exist in memory then
i. Check for any empty frames.
ii. If there is an empty frame,
Assign that frame to the page
Store incremented freq for that page position in access array.
Increment count.
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor, flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10].optcal[50].count=0;
int optvictim();
void main()
{
clrscr();
printf(“\n OPTIMAL PAGE REPLACEMENT ALGORITHN");
printf("\n........................................................... ”);
printf ("\n Enter the no.of frames");
scanf("%d",&nof);
printf("Enter the no.of reference string"):
scanf("%d",&nor);
printf("Enter the reference string");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]):
clrscr();
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHM"):
printf("...................................................................... ”);
printf("\n................................. ”);
for(i=0;i<nor;i++)
printf("%4d".ref[i]);
for(i=0;i<nof;i++)
{
frm[i]=-1;
optcal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
flag=0
printf("\n\tref no %d ->\"ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
break;
}
if flag==0){ count++;
if(count<=nof)
victim++;
else victim=optvictim(i);
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d" frm[j]);
}
}
printf("n Number of page faults: %d",pf);
getch();
}
int optvictim(int index)
{
int i,j,temp,notfound;
for(i=0;i<nof;i++)
{
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
{
notfound=0;
optcal[i]=j;
break;
}
if (notfound==1)
return i;
}
temp=optcal[0];
for(i=1;i<nof;i++)
if temp<optcal[i])
temp=opical[i];
for(i=0;i<nof;i++)
if frm[temp]==frm[i])
return i;
return 0;
}
OUTPUT:
……………………6 5 4 2 3 1
Reference NO 6-> 6 -1 -1
Reference 6 5 -
NO 5-> 1
Reference 6 5 4
NO 4->
Reference 2 5 4
NO 2->
Reference 2 3 4
NO 3->
Reference 2 3 1
NO 1->
RESULT:
Thus the program optimal page replacement algorithm has been implemented and outputis verified
successfully.
EXP No : 13(a)
SINGLE LEVEL DIRECTORY USING FILE ORGANIZATION
DATE :
AIM:
ALGORITM:
Step 1 : Start
Step 2 : Get name of directory for the user to store all the files
Accept filename
Accept filename
#include<stdio.h>
Struct
{
char dname[10]fname[10][10];
int fcnt;
}dir;
void main()
int i,ch;
char f[30];
clrscr();
dir.fcnt = 0;
printf("Enter name of directory --");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n l. Create File \t2. Delete File\t3. Search File \n4. Display Files \t5. Exit\nEnter yourchoice--");
scanf("%d", &ch);
switch(ch)
{
case 1:
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++:
break;
case 2:
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f,dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
}
if(i==dir.fcnt)
--
break;
case 3:
printf("\n Enter the name of the file"--");
scanf("%s" f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir.fname[i])==0)
printf("File %s is found ", f);
break;
}
break;
case 4:
if(dir.fcnt==0)
printf("nDirectory Empty");
else
{
printf("\nThe Files are --");
for(i=0;i<dir.fcnt; i++)
printf("%s",dir.fname[i]);
}
break;
default;exit(0);
}
getch();
}
OUTPUT:
1. Create File
4. Display Files
5. Exit
Enter your choice -1
1. Create File
5. Exit
Enter your choice -1
1. Create File
4. Display Files
5. Exit
Enter your choice -1
1. Create File
4. Display Files
5. Exit
Enter your choice -4The Files are -A B C1.Create File
2. Delete File
3. Search File
4. Display Files
5. Exit
Enter your choice -3
1. Create File
2. Delete File
3. Search File
4. Display Files
5. Exit
Enter your choice -2
1. Create File
2. Delete File
3. Search File
4. Display Files
5. Exit
Enter your choice -5
RESULT:
Thus the program has been implemented and output is verified successfully.
EXP No : 13(b)
TWO LEVEL DIRECTORY USING FILE ORGANIZATION
DATE :
AIM:
ALGORITHM:
If directory exist then accept filename without collision else report error
If file exist in that directory then delete entry else report error
If file exist in that directory then Display filename else report error
Struct
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
int i,ch,dcnt,k;
clrscr();
dcnt=0;
while(1)
printf("\n4. Search File\t\t5. Display \t6. Exit \tEnter your choice --");
scanf("%d", &ch);
switch(ch)
case 1:
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
case 2:
printf("Enter name of the directory --");
scanf("%s",d):
for(i=0;i<dcnt;i++)
if(strcmp(d.dir[i].dname)==0)
{
scanf("%s",dir[i].fname[dir[i]_fcnt]);
dir[i].fcnt++;
break;
if(i==dcnt)
break;
case 3:
scanf( "%s",d);
for(i=0;i<dcnt;i++)
if (strcm
p(d,dir[i].dname)==0)
{
for(k=0;k<dir[i], fcnt;k++)
{
if stremp(f, dir[i].fname[k])==0)
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}
}
goto jmp;
}
}
jmp: break;
case 4:
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f,dir[i].fname[k])==0)
goto jmp1;
}
}
goto jmp 1;
break;
case 5:
if(dcnt==0)
else
for(i=0;i<dent;i++)
printf ("\t%s",dir[i].dname);
for(k=0;k<dir[i].fent;k++)
break;
default:exit(0);
getch();
}
OUTPUT:
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --1
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --1
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice -2
Enter name of the directory –DIRIEnter name of the file--Al
File created
1. Create Directory
2. Create File 3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --2
File created
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --2
File created
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice –2
File created
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --5Directory Files
DIR1
Al A2 DIR2BI
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --4
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice --3
File A2 is deleted
1. Create Directory
2. Create File
3. Delete File
4. Search File
5. Display
6. Exit
Enter your choice –6
RESULT:
Thus the program two level directory using file organization has been implemented andoutput is
verified successfully.
EXP No : 14(a)
SEQUENTIAL FILE ALLOCATION
DATE :
AIM:
ALGORITHM:
Step 1:Assume no. of blocks in the disk as 20 and all are free.
c. Check to see whether any block in the range (start, start + length-1) is allocated. If so,
then go to step 2.
d. Allocate blocks to the file contiguously from start block to start + length - 1.
Step 6:Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&b[i]);
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1.t[i].b[i]);
scanf("%d",&x);
printf("blocks occupied:");
for(i=0;i<b[x-1];i++)
printf("%4d",c[x-1][i]);
getch();
}
OUTPUT:
1 2 4
2 5 10
RESULT:
Thus the program sequential file allocation has been implemented and output is verified
successfully.
EXP No : 14(b)
INDEXED FILE ALLOCATION
DATE :
AIM:
ALGORITHM:
Step 2:Accept filenames and no, of blocks fo each fileStep 3: Obtrain start block for each file
Step 9: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
main(){
int ,n,m[20],i,j,sb[20],s[20],b[20][20],x;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&sb[i],&s[i]);
scanf("%d",&m[i]);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
printf("\nFile\t index\length\n");for(i=0;i<n;i++){
scanf("%d", &x);
i=x-1;
printf("Index is:%d",sb[i]);
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
getch();
}
OUTPUT:
2 5 4 6 7 2 6 4 7
1 2 10
2 3 5
RESULT:
Thus the program indexed file allocation has been implemented and output is verified
successfully.
EXP No : 14(c)
LINKED FILE ALLOCATION
DATE :
AIM:
ALGORITHM:
Step 9: Stop
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct file
char frame[10];
int start,size,block[10];
}f[10];
scanf ("%d",&n);
for(i=0;i<n;i++){
scanf("%s",&f[i].fname);
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
scanf("%d",&f[i].size);
for(j=1;j<=f[i].size;j++){
scanf("%d",&f[i].block[j]);
printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t" f[i].fname,f[i].start.f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf(“%d--->”f[j]);
printf(“%d”f[i].block[j]);
printf(“\n);
getch();
}
OUTPUT:
Enter no of files:2
Enter file name:venkat
Enter starting block:20
Enter no.of blocks:6
Enter block numbers: 4
12
15
45
32
25
rajesh 12 5 6--5---4---3--->2
RESULT:
Thus the program linked file allocation has been implemented and output is verifiedsuccessfully.
EXP No : 15(a)
FCFS DISK SCHEDLING
DATE :
AIM:
ALGORITHM:
Step 1.Define an array of structure process with members pid, btime, wtime & ttime
.Step 2.Get length of the ready queue, i.e., number of process (say n).
a. wtimei+1= wtime,+btimei
b. ttime =wtimei+btimei
Step 6. Compute average waiting time awat and average turnaround time atur
process.
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,n,TotalHeadMoment=0,initial;
scanf("%d",&n);
;for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
for(i=0;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
}
OUTPUT:
50
RESULT:
Thus the program FCFS disk scheduling has been implemented and output is verifiedsuccessfully.
EXP No : 15(b)
SSTF DISK SCHEDULING
DATE :
AIM:
ALGORITHM:
Step 1.Define an array of structure process with members pid, btime, wtime & ttime.
Step 2.Get length of the ready queue, i.e., number of process (say n).
a. wtimei+1= wtime,+btimei
b. ttime =wtimei+btimei
Step 6. Compute average waiting time awat and average turnaround time atur
process.
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],in, TotalHeadMoment=0,initial,count=0;
printf ("Enter the number of Requests\n");
scanf(“%d”,&n);
scanf ("%d",&initial);
while(count!=n)
int min=1000,d,index;
for(i=0;i<n;i++)
if(min>d)
min=d;
index=i:
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index]:
count++;
}
printf ("Total head movement is %d”,TotalHeadMoment);
return 0;
OUTPUT:
RESULT:
Thus the program sstf disk scheduling has been implemented and output is verifiedsuccessfully.
EXP No : 15(c)
SCAN DISK SCHEDULING
DATE :
AIM:
ALGORITHM:
Step 1.Define an array of structure process with members pid, btime, wtime & ttime.
Step 2.Get length of the ready queue, i.e., number of process (say n).
a. wtimei+1= wtime,+btimei
b. ttime =wtimei+btimei
Step 6. Compute average waiting time awat and average turnaround time atur
process.
#include<stdi o.h>
#include<math.h>
int main()
float avg;
scanf(“%d”,&max);
scanf(“%d”, &head);
scanf(“%d”,&n);
Scanf(“%d”,&tem
p);
queue1[temp1] = temp;
temp1++;
else
queue2[temp2] =
temp;temp2++;
}
{
If (queue l[i]> queue l [j])
queue1[i]
=queue1[j];
queue1[j] =temp;
if(queue2[i]< queue2[j])
temp = queue2[i];
queue2[i] =
queue2[i];queue2[j]
= temp;
}}
queue[i] = queue1[j];
queue[i] = max;
for (i=templ + 2, j = 0;
seek += diff;
diff);
return 0;
}
OUTPUT:
RESULT:
Thus the program scan disk scheduling has been implemented and output is verifiedsuccessfully.
EXP No : 16
INSTALL ANY GUEST OPERATING SYSTEM LIKE LINUX USING
VMWARE
DATE :
AIM
ALGORITHM:
Step 1: Download the VMWare workstation. Set up is around 307 MB. Currently, version 12 isavailable.
Please note we have set up screens on version 11.
Step2: Install VMWarre on your machine. Setup is simple and requires clicking NextButton a couple of
times.
Step3: After installation open the VMWare workstation by using either the start menu orshortcut created
on the desktop.
Step7: In the Next step you need to specify a key or a serial number of the operating system.If you are
using the version then that part can be skipped.
Step8: Enter the names for the virtual machine and specify a path to the directory where you want to
create your virtual machine. It is recommended that the drive you’re selecting to install avirtual machine
should have sufficient space.
Step9: Specify the amount of disk space you want to allocate for a virtual machine.
Allocate disk space according to the size of the software you are going to install on the virtualmachine.
Step10:On the next screen it will show the configuration you selected for a virtual machine.
Step11:It will allocate Hardware according to the default setting but you can change it byusing Customize
button in the above screen.
You can specify what amount of RAM. A processor has to be allocated for a virtual machine. Do not
allocate complete RAM or a complete Processor for a virtual machine. Also, donot allocate very little
RAM or processor. Leave default setting or allocate in such a way that your application should be able to
run on the virtual machine. Else it will result in a show virtualmachine.
Step12:Click on the Finish button to create the virtual machine at the specified location andwith specified
resources.
If you have specified a valid file (.iso, .rar., .nrg) for the operating system it will take standard
time to complete the operating system setup on the virtual machine, and then it will be ready to use your
regular OS