os lab full
TRANSCRIPT
-
8/2/2019 OS LAB FULL
1/63
UNIX COMMANDS
AIM: To study and execute the commands in unix.
COMMANDS:
1. DATE command:This command is used to disp;ay the current date and time.Syntax:
$date$date+%d
Options:a=abbrevated weekdayA=Fully weekdayb=abbrevated monthB=full monthC=current day and timeC=display the century as a decimal numberD=day of the monthD=day in mm/dd/yy formatH=abbrevated month dayH=display the hourL=day of the yearM=month of the yearM=minuteP=display AM or PMS=secondsT=HH:MM:SS formatU=week of the yearY=display the year in 2 digitZ=time zone
To change the format:Syntax:$date+%H-%M-%s
2.CAL -calander command:
This command is used to display the calendar of the year of theparticular month of calendar year.
Syntax:a.$cal
-
8/2/2019 OS LAB FULL
2/63
b.$calhere the first syntax gives the entire calendar for given year and the second syntax givesthe calendar of reserved month of that year.
3.ECHO command:
This command is used to print the arguments on the screen.Syntax:
$echo
Multiline echo command:
1.To have the output in the same line, the following commands can beused.Syntax:
$echotext
2.to have the output in different line, the following command can beused.Syntax:
$echotext>line2>line3
4.BANNER command:
It is used to display the arguments in # symbol.Syntax:
$banner
5.WHO command:
It is used to display who are the users connected to our computer.Syntax:
$who- optionsOptions:
H-display the output with headers.
b-display the latest booting date or time when the system was lastly rebooted.6.WHO AM I command:
Display the details of the current working directory.Syntax:
$who am i
7.ttycommand:
It will display the terminal name.
-
8/2/2019 OS LAB FULL
3/63
Syntax:
$tty
8.Binarycalculator command:
It will change the $ mode and in the new mode, arithmetic operationssuch as +,-,*,/,%,n,sqrt(),length(),=,etc can be performed. This command is used to goto the binary calculus mode.Syntax:
$bcOperations^d$
I base-input baseO base-output base are used for base conversions
Base:Decimal=1Binary=2Octal=8Hexa=16
9.CLEAR command:
It is used to clear the screen.Syntax:
$clear
10.MAN command:
It help us to know about the particular command and its options andworking. It is like help command in window.Syntax:
$man
11.Manipulation command:
It is used to manipulate the screen.Syntax:%tput
Arguments:
1.clear-to clear the screen.2.longname-display the complete name of the terminal.3.SMSO-background become white and foreground become black colour.4.rmso-background become black and foreground become white colour.5.cop RC-move to the cursor position to the specified location.6.cols-display the number of columns in our terminals
.
-
8/2/2019 OS LAB FULL
4/63
12.List command:
It is used to list all the contents in the current working directory.Syntax:
$ls-optionsIf the command does not contain any argument means it is working in the current
directory.Options:
a-used to list all files including the hidden files.e-list all the files column wise.d-list all the directories.m-list the files separated by commas.p-list files include/to all 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:
1.PWD command:
To print the complete path of the current working directory.Syntax:
$pwd
2.MKDIR command:
To create or make a new directory in a current directory.Syntax:
$mkdir
3.CD command:
To change or move the directory to the mentioned directory.Syntax:
$cd
4.RMDIR command:
To change or move the directory to the mentioned directory.Syntax:
$rmdir
5.CD command:
To move the previous directory or the present directory.Syntax:
$cd
-
8/2/2019 OS LAB FULL
5/63
FILE RELATED COMMANDS:
1.create a file:
To create a new file in the current directory we use CAT command.Syntax:
$cat>file nameThe >symbol is redirectory we use cat command.
2.Display a file:
To display the content of file mentioned we use CAT command without >operator.Syntax:
$cat>
$cat>>It is avoid overwritting.Options:
-n content of files with numbers included with blank lines.Syntax:
$cat-n
4.Sorting a file:
To sort the contents in alphabetical order in reverse order.Syntax:
$sortOptions:
$sort-r
5.Copying Contents from one file to another:
To copy the contents from source to destination file. So the both contents aresame.
-
8/2/2019 OS LAB FULL
6/63
Syntax:
$cp$cp
6.MOVE command:
To completely move the contents from source file to destination file and toremove the source file.Syntax:
$mv
7.REMOVE command:
To completely move the contents from source file to destination file and toremove the source file.
Syntax:$rm
8.WORDS command:
To list the count of no of lines, words, characters.Syntax:
$wcOptions:
-c to display the no of characters.-l to display only the lines.-w to display the no of words
.9.Line printer:
To print the line through the printer, we use lp command.
Syntax:
$lp
10.PAGE command:
Thes command is used to display the contents of the file page wise and nextpage can be viewed by pressing the enter key.Syntax:
$pg
-
8/2/2019 OS LAB FULL
7/63
RESULT:
Thus the basic commands of unix are studied and verified.
-
8/2/2019 OS LAB FULL
8/63
UNIX SHELL COMMANDS
AIM:
To syudy about the UNIX shell programming commands.
INTRODUCTION:
Shell programming is a group of commands together under under signal filename.
1.SHELL KEYWORDS:
Echo, read, if, else, case, esac, for, while, do, done, until, set, unset, readonly,shift, export, break, continue, exit, return, trap, wait, eval, exec, unlimit, unmask.
2.SHELL VARIABLES:
Shell variables change during the executing of the program.
Rules:
1.A variable name is any combination of alphabets, digits and an underscore(_).2.No commas or blank space are allowed within a variable name.3.The first character of a variable name must be an alphabet or an underscore(_).4.Variables names should be of any reasonable length.5.Variables name are case sensitive. That name, NAME, Name are all differentvariables.
3.READ STATEMENT:
To get the input from the user.
Syntax: read x y
[no need commas between variables]
4.ECHO STATEMENT:
Echo statement is similar to the output statement.Syntax:
Echostring(or)
Echo$b[for variables]
-
8/2/2019 OS LAB FULL
9/63
5.EXP-Expression Command:
To perform all arithmetic operations.
Syntax:
Var=`expjjr $value 1 `+`$value 2`
6.NESTING OF EXPRESSION COMMAND:
Syntax:
Sum=expr `$value 1+$value 2`+value 3
7.ARITHMETIC OPETRATORS:
+,-,/,*,%,^
8.RELATIONAL OPERATORS:
-le : less than (or) equal to.-lt : less than.-gl : greater then (or) equal to.-dt : greater than.-eq : equal to.
9.LOGICAL OPERATORS:
And : &&Or : ||
10.EXECUTION OF SHELL SCRIPT:
1.By using change mode command.2.$chmod u + x sum sh3.$sum.sh
(or)
$ch sum.sh
11.CONDITIONAL STATEMENT:
(i)If Statement:
This is used to check a condition and if it satisfy the condition if then does thenext action, if not it goes to the else part.
(ii)IF.ELSE.Statement:
Syntax:
if cp $source $targetthen
-
8/2/2019 OS LAB FULL
10/63
echo file copied successfullyelseecho failed to copy the file
(iii) NESTED IF Statement:
Here sequence of condition are checked and the corresponding performedaccordingly.Syntax:
if conditionthencommandif conditionthencommandelse
commandfifi
(iv) CASEESAC Statement:
This construct helps in execution of shell script based on choice.
12.UNTIL loop:
This loop is similar to while loop except that it continues as long as thecontrol connand file.Syntax:
until control commanddocommandone
13.BREAK statement:
This command is used to jump out the loop instantly, without waiting to
get the control command.
Result:
Thus the unix shell commands are executed and verified.
-
8/2/2019 OS LAB FULL
11/63
VI EDITOR COMMANDS
AIM:
To study the various commands operated in vi editor in unix.
COMMANDS:
Starting vi:
The vi editor is invoked by giving the following commands in unix prompt.Syntax:
$vi(or)$vi
This command would open a display screen with 25 lines and withtilde(~) symbol at the start of each line. The first syntax would save the file in thefilename mentioned and for the next the filename must be mentioned at the end.Options:
1.vi+n-this would point at the nth line(cursor pos).2.vi-n-this command is to make the file to read only to change
from one made to another press escape key.
INSERTING AND REPLACING COMMANDS :
To move editor from command mode to edit mode, you have to press the key.
For inserting and replacing the following commands are used.1.a command:
This command is used to move the edit mode and start to append after thecurrent character.Syntax:
a
2.A command:
This command is also used to append the file, but this command append at theend of current line.Syntax:
A3.i command:
This command is used to insert the text before the current cursor position.
Syntax:
-
8/2/2019 OS LAB FULL
12/63
i
4.I command:
This command is used to insert the text at the beginning of the current line.
Syntax:I
5.o command:
This command is to insert a blank line below the current line and allowinsertion of contents.Syntax:
o
6.O command:
This command is used to insert a blank line above and allow the insertion ofcontents.Syntax:
O
7.r command:
This command is used to replace the particular character with the givencharacters.Syntax:
r xWher x is the new character.
8.R command:
This command is used to replace the particular text with a given text.Syntax:
R text
9.s command:
This command is used to replace a single character with a group ofcharacters.Syntax:
s
10.S command:
This command is used to replace a current line with group of characters.Syntax:
S
-
8/2/2019 OS LAB FULL
13/63
CURSOR MOVEMENT IN VI:
1.L:
This command is used to move to the previous character typed. It is used tomove to left of the text. It can also be used to move character by character (or) a numberof characters.Syntax:
L-to move one character to leftnL-to move n characters to left
2.I:
This command is used to move to the right of the cursor (i.e.) to the next
character. It can also be used to move the cursor for a number of characters.Syntax:I-single character to rightnI- n character to right
3. j:
This command is used to move down a single line or a number of lines.Syntax:
j- single down movementnj- n times down movement
4. k:
This command is used to move up a single line or a number of lines.Syntax:
k- single line abovenk- n lines above
5.ENTER (OR) ENTER:
This command will move the cursor to the starting of next lines or a group of
lines mentioned.Syntax:
enternenter
6. + command:
This command is used to move to the beginning of the next line.Syntax:
+n+
7. - command:
-
8/2/2019 OS LAB FULL
14/63
This command is used to move to the beginning of the previous line.
Syntax:
-n-
8. o command:
This command will bring the cursor to the beginning of the same current line.Syntax:
o
9. $ command:
This command will bring the cursor to the end of the current line.Syntax:
$
10. ^ command:
This command is used to move to first character of first lines.Syntax:
^
11. b command:
This command is used to move back to the previous word (or) a number of words.Syntax:
bnb
12. e command:
This command is used to move towards and replace the cursor at last character ofthe word (or) no of words.Syntax:
e
ne
13. w command:
This command is used to move forward by a single word or a group of words.Syntax:
wnw
DELETING THE TEXT FROM VI:
1. x command:
-
8/2/2019 OS LAB FULL
15/63
To delete a character to right of current cursor positions, this command is used.
Syntax:
x
nx
2. X command:
To delete a character to left of current cursor positions, this command is used.Syntax:
XnX
3. dw command:
This command is to delete a single word or number of words to right of currentcursor position.Syntax:
dwndw
4.db command:
This command is to delete a single word to the left of the current cursor position.Syntax:
dbndb
5.dd command:
This command is used to delete the current line (or) a number of line below thecurrent line.Syntax:
ddndd
6.d$ command:
This command is used to delete the text from current cursor position to lastcharacter of current lineSyntax:
d$
SAVING AND QUITING FROM VI:
1.w command:
-
8/2/2019 OS LAB FULL
16/63
To save the given text present in the fileSyntax:
:w
2.q! command:
To quit the given text without saving.Syntax:
:q!
3.wq command:
This command quits the vi editor after saving the text in the mentioned file.Syntax:
:wq
4.x command:
This command is same as wq command it saves and quitSyntax:
x
5.q command:
This command would quit the window but it would ask for again to save the file.Syntax:
q
RESULT:
Thus the Vi editor commands are studied and verified.
PROGRAM:
#includemain()
-
8/2/2019 OS LAB FULL
17/63
{int pid1,pid2,pid3;
printf("parent id is %d and root id is%d\n",getpid(),getppid());pid1=fork();if(pid1==0)
{printf("process 1 id is %dand its parent id id%d\n",getpid(),getppid());pid2=fork();}if(pid2==0){
printf("process 2 id is%d and its parent id is%d\n",getpid(),getppid());pid3=fork();}if(pid1==0&&pid2==0&&pid3==0){
printf("process 3 id is %d and its parent id is%d\n",getpid(),getppid());}}
OUTPUT:
[user@localhost cse]$ cc fork.c[user@localhost cse]$ ./a.out
-
8/2/2019 OS LAB FULL
18/63
Process id is 6901Parent id is 6900
PROGRAM:
#include
-
8/2/2019 OS LAB FULL
19/63
#include#includemain(){int pid1;
pid1=fork();if(pid1==0){
printf("process id is %d",getpid());printf("and its parent id is %d",getppid());execl("/bin/who","who",0);}}
OUTPUT:
-
8/2/2019 OS LAB FULL
20/63
[user@localhost cse]$ cc exec.c[user@localhost cse]$ ./a.out
Parent id is 6407And root id is 5638
Process1 id is 6408And its parent id is 6407Process2 id is 6409And its parent id is 6408Process3 id is 6410And its parent id is 6409
PROGRAM:
#include#include
-
8/2/2019 OS LAB FULL
21/63
#include#include#includemain(){
int fd1,fd2,n;char source[30],ch[5];struct stat s,t,w;fd1=creat("test.txt",0644);
printf("Enter the file to be copied\n");scanf("%s",source);fd2=open(source,0);if(fd2==-1){
perror("file does not exist");exit(0);
}while((n=read(fd2,ch,1))>0)write(fd1,ch,n);close(fd2);stat(source,&s);
printf("Source file size=%d\n",s.st_size);fstat(fd1,&t);
printf("Destination file size before closing=%d\n",t.st_size);close(fd1);fstat(fd1,&w);
printf("Destination file size after closing=%d\n",w.st_size);}
OUTPUT:
[user@localhost cse]$ cc exit.c[user@localhost cse]$ ./a.out
-
8/2/2019 OS LAB FULL
22/63
Enter file to be copied: sts1.cSource file size: 670Destination file size before closing: 670Destination file size after closing: 3
PROGRAM:
#include
-
8/2/2019 OS LAB FULL
23/63
#includemain(){DIR *p;struct dirent *dp;
p=opendir(".");if(p==NULL){
perror("opendir");exit(0);}dp=readdir(p);while(p!=NULL){
printf("%d%s\n",dp->d_ino,dp->d_name);dp=readdir(p);
}}
OUTPUT:
[user@localhost cse]$ cc opendir.c
-
8/2/2019 OS LAB FULL
24/63
[user@localhost cse]$ ./a.out
8247573082418 a.out82420 fork.c
PROGRAM:
#include
-
8/2/2019 OS LAB FULL
25/63
#includevoid first();void second();int pid;main()
{pid=fork();if(pid!=0){printf("221");printf("\nWelcome...");sleep(3);signal(SIGUSR2,first);kill(pid,SIGUSR1);}else
{signal(SIGUSR1,second);}sleep(4);
}void first(){
printf("\nKilling...\nfirst kill\n");exit(0);}void second(){printf("\nKilling...\nsecond killed\n");kill(pid,SIGUSR2);
}
OUTPUT:
[user@localhost cse]$ cc system.c
-
8/2/2019 OS LAB FULL
26/63
[user@localhost cse]$ ./a.out
221Killing...second killed
Welcome...Killing...first kill
PROGRAM:
#includemain()
-
8/2/2019 OS LAB FULL
27/63
{FILE *ptr,*ptw;char ch;ptw=fopen("hai.c","wf");printf("Enter the text:");
printf("\nFor save and exit press ctrl+D\n");while((ch=getchar())!=EOF){fputc(ch,ptw);if(ch==EOF)exit();}fclose(ptw);printf("\nYour text:");ptr=fopen("hai.c","r");while((ch=fgetc(ptr))!=EOF)
printf("%c",ch);fclose(ptr);
}
OUTPUT:
[user@localhost cse]$ cc read.c
-
8/2/2019 OS LAB FULL
28/63
[user@localhost cse]$ ./a.out
Enter the text:For save and exit press ctrl+Dhai how r u?
Your text: hai how r u?
-
8/2/2019 OS LAB FULL
29/63
PROGRAM:
#include#includeint main()
{struct dirent **namelist;int n,i;char pathname[100];getcwd(pathname);n=scandir(pathname,&namelist,0,alphasort);if(n
-
8/2/2019 OS LAB FULL
30/63
OUTPUT:
[user@localhost cse]$ cc ls.c[user@localhost cse]$ ./a.out
...a.out ls.c
-
8/2/2019 OS LAB FULL
31/63
PROGRAM:
#include#include#include
#includeint calc_bufsize(char *filename){struct stat st;stat(filename,&st);return((int)st.st_size);
}int main(int argc,char *argv[]){if(argc
-
8/2/2019 OS LAB FULL
32/63
OUTPUT:
[user@localhost cse]$ cc grep.c[user@localhost cse]$ ./a.out
usage:...
-
8/2/2019 OS LAB FULL
33/63
PROGRAM:
#includemain(){
int n,b[12],b1[12],w[12],e[12],i,k,t;float aw=0,at=0;printf("Enter the no of jobs:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
34/63
OUTPUT:
[user@localhost cse]$ cc fcfs.c[user@localhost cse]$ ./a.out
Enter the no of jobs: 3
Enter the burst time for job123Enter the burst time for job212Enter the burst time for job35
Job Burst Waiting Turnaround1 23 0 232 12 23 353 5 35 40
Average waiting time is: 19.333334Average turnaround time is: 32.666668
-
8/2/2019 OS LAB FULL
35/63
PROGRAM:
#includemain(){
int n,b[12],b1[12],w[12],e[12],i,k,t;float aw=0,at=0;printf("Enter the no of jobs:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
36/63
OUTPUT:
[user@localhost cse]$ cc sjf.c[user@localhost cse]$ ./a.out
Enter the no of jobs:3
Enter the burst time for job123Enter the burst time for job212Enter the burst time for job35
Job Burst Waiting Turnaround1 5 0 52 12 5 173 23 17 40
Average waiting time is: 7.333333Average turnaround time is: 20.666666
-
8/2/2019 OS LAB FULL
37/63
PROGRAM:
#includemain(){
int n,b[12],b1[12],w[12],e[12],pri[12],i,k,t;float aw=0,at=0;printf("\nEnter the no of jobs:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
38/63
printf("\nAverage turnaround time is:%f",at);return(0);
}
-
8/2/2019 OS LAB FULL
39/63
OUTPUT:
[user@localhost cse]$ cc priority.c[user@localhost cse]$ ./a.out
Enter the no of jobs: 4
Enter the burst time and priority for jobs: 145Enter the burst time and priority for jobs: 267Enter the burst time and priority for jobs: 375Enter the burst time and priority for jobs: 437
Jobs Burst Priority Start time Finish time1 4 5 0 42 7 5 4 113 6 7 11 174 3 7 17 20
Average waiting time is: 8.000000Average turnaround time is: 13.000000
-
8/2/2019 OS LAB FULL
40/63
PROGRAM:
#includemain(){
int i,n,j=0,p[15],ts,tt=0,b[15];printf("Enter the no of process:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
41/63
OUTPUT:
[user@localhost cse]$ cc robin.c[user@localhost cse]$ ./a.out
Enter the no of process: 4
Enter the process name: 1Enter the burst time for the process: 8Enter the process name: 2Enter the burst time for the process: 12Enter the process name: 3Enter the burst time for the process: 4Enter the process name: 4Enter the burst time for the process: 16
Enter slice time: 4
PROCESS NAME REMANING TIME TOTAL TIME1 4 42 8 83 0 124 12 161 0 202 4 244 8 28
2 0 324 4 364 0 40
-
8/2/2019 OS LAB FULL
42/63
PROGRAM:
#include#include#include
int main(){int child,shmid,i;char *shmptr;child=fork();if(!child){shmid=shmget(2041,32,0666/IPC_CREATE);shmptr=shmat(shmid,0,0);printf("\n PARENT WRITING\n");for(i=0;i
-
8/2/2019 OS LAB FULL
43/63
OUTPUT:
[user@localhost cse]$ cc shared.c[user@localhost cse]$ ./a.out
PARENT WRITINGabcdefghijabcdefghij
CHILD IS READING: abcdefghij
-
8/2/2019 OS LAB FULL
44/63
PROGRAM:
#includeint main(){
int fd[2],child;char a[10];printf("\nEnter the string to enter into the pipes:");scanf("%s",a);pipe(fd);child=fork();if(!child){close(fd[0]);write(fd[1],a,5);wait(0);}else{close(fd[1]);read(fd[0],a,5);printf("\nThe string reterived from the pipe is:%s",a);}return 0;
}
-
8/2/2019 OS LAB FULL
45/63
OUTPUT:
[user@localhost cse]$ cc pipe.c[user@localhost cse]$ ./a.out
Enter the string to enter into the pipes: computerThe string retrieved from the pipe is: computer
-
8/2/2019 OS LAB FULL
46/63
PROGRAM:
#includeint currentsize;int n;
main(){int ch;printf("\nEnter the size of the buffer:");scanf("%d",&n);do{printf("\n1.Producer\n2.Consumer\n3.Exit\nEnter your choice:\n");scanf("%d",&ch);switch(ch){case 1:
producer();break;
case 2:consumer();break;
}}while(ch!=3);
}producer()
{int item;printf("\nEnter the no of items to be produced:");scanf("%d",&item);if(0=pdt){currentsize=currentsize-pdt;printf("\nThe items has been consumed");
printf("\nThe no of items in the buffer is %d",currentsize);}
-
8/2/2019 OS LAB FULL
47/63
-
8/2/2019 OS LAB FULL
48/63
OUTPUT:
[user@localhost cse]$ cc producer.c[user@localhost cse]$ ./a.out
Enter the size of the buffer: 20
1. Producer2. Consumer3. Exit
Enter your choice:1
Enter the no of items to be produced: 17
The item has been producedThe no of items in the buffer is 171. Producer2. Consumer3. Exit
Enter your choice:2
Enter the no of items to be consumed: 14
The items has been consumed
The no of items in the buffer is 31. Producer2. Consumer3. Exit
Enter your choice:3
-
8/2/2019 OS LAB FULL
49/63
PROGRAM:
#includemain(){
int a[20],p[20],i,j,n,m,t;printf("\nEnter the no of blocks:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
50/63
}}}for(j=0;j
-
8/2/2019 OS LAB FULL
51/63
OUTPUT:
[user@localhost cse]$ cc bestfit.c[user@localhost cse]$ ./a.out
Enter the no of blocks: 3
Enter the 0 of block size: 300Enter the 1 of block size: 200Enter the 2 of block size: 100
Enter the no of process3
Enter the size of 0 of process: 100Enter the size of 1 of process: 300Enter the size of 2 of process: 200
The process 0 allocated to 100The process 1 allocated to 300The process 2 allocated to 200
-
8/2/2019 OS LAB FULL
52/63
PROGRAM:
#includemain(){
int a[20],p[20],i,j,n,m;printf("\nEnter the no of blocks:");scanf("%d",&n);for(i=0;i
-
8/2/2019 OS LAB FULL
53/63
OUTPUT:
[user@localhost cse]$ cc first.c[user@localhost cse]$ ./a.out
Enter the no of blocks: 5
Enter the 0 of block size: 500Enter the 1 of block size: 400Enter the 2 of block size: 300Enter the 3 of block size: 200Enter the 4 of block size: 100
Enter the no of process:5
Enter the size of 0 of process: 100Enter the size of 1 of process: 350Enter the size of 2 of process: 400Enter the size of 3 of process: 150Enter the size of 4 of process: 200
The process 0 allocated to 500The process 1 allocated to 400The process 3 allocated to 300The process 4 allocated to 200
The process 2 is not allocated
-
8/2/2019 OS LAB FULL
54/63
PROGRAM:
#includeint main(){
int i,j,n,a[50],frame[10],no,k,avail,count=0;printf("\nEnter the no of pages:\n");scanf("%d",&n);printf("\nEnter the page number:\n");for(i=1;i
-
8/2/2019 OS LAB FULL
55/63
OUTPUT:
[user@localhost cse]$ cc fifo.c[user@localhost cse]$ ./a.out
Enter the no of pages:5
Enter the page number:32145
Enter the number of frames: 2
Ref string Page frame3 3 -12 3 21 1 24 1 45 5 4
Page fault is: 5
-
8/2/2019 OS LAB FULL
56/63
PROGRAM:
#includemain(){
int nframes,len,k,u,min,rep,pos[20],i,j=1,t,m,flag,pf=0,frame[20],s[20];printf("Enter no of frames\n");scanf("%d",&nframes);for(i=1;i
-
8/2/2019 OS LAB FULL
57/63
}elseframe[j++]=s[i];
}for(k=1;k
-
8/2/2019 OS LAB FULL
58/63
OUTPUT:
[user@localhost cse]$ cc lru.c[user@localhost cse]$ ./a.out
Enter no of frames3Enter length of reference string9Enter reference string123456789
1 -1 -11 2 -11 2 34 2 34 5 34 5 6
7 5 67 8 67 8 9
No. of page faults is 9
-
8/2/2019 OS LAB FULL
59/63
PROGRAM:
#include#define MAX 20main()
{int block_size[MAX],file_size[MAX],no_of_blocks,no_of_files;int temp,highest=0;static int block_flag[MAX],file_flag[MAX];int i,j;
printf("\n enter the no of blocks");scanf("%d",&no_of_blocks);for(i=1;i
-
8/2/2019 OS LAB FULL
60/63
OUTPUT:
[user@localhost cse]$ cc worst.c[user@localhost cse]$ ./a.out
enter the no of blocks3
enter the size of memory block1:15
enter the size of memory block2:16
enter the size of memory block3:17
enter the number of files:2
enter the size of file1:12
enter the size of file2:14
file number file size block number block size1 12 3 172 14 3 17
[user@localhost cse]$
-
8/2/2019 OS LAB FULL
61/63
SRINIVASA INSTITUTE OF ENGINEERING & TECHNOLOGY
P A R I V A K K A M
CHENNAI-600056
CS2257 OPERATING SYSTEMS LAB RECORD
REGISTER NUMBER:
-
8/2/2019 OS LAB FULL
62/63
SRINIVASA INSTITUTE OF ENGINEERING AND T ECHNOLOGY
P A R I V A K K A M
C H E N N A I - 6 0 0 0 5 6
REGISTER NUMBER:
BONAFIDE CERTIFICATE
Certified that this is a bonafide record of the work done by
--------------------------------------------------Of Second Year (4th Semester) of
-------------------------------------------- Department in the Operating Systems Laboratory
(CS 2257) during academic year 2009- 2010
Signature of the Staff Signature of HOD
Submitted for the Practical Examination held on ----------------------------
External Examiner Internal Examiner
-
8/2/2019 OS LAB FULL
63/63
INDEX
EX.
NO
DATE NAME OF THE EXPERIMENT PAGE
NO.
T. SIGN