Documente Academic
Documente Profesional
Documente Cultură
DATE :
BASIC COMMANDS IN LINUX
COMMANDS
S M T W T F S
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
Aim
Write programs using the following system calls of UNIX operating system: fork,
exec, getpid, exit, wait, close, stat, opendir, readdir.
Algorithm
Step 2: Get the getpid value from system using printf ststement.
Step 4: The fork () function creates a new process. The new process (child process) is
Step 5: If pid1 is equal to zero then assign getpid() to pid1 and display “ I am always
#include<stdio.h>
main()
{
int pid1;
printf("I am the main process:%u\n",getpid());
printf("clear(garbage value):%u\n",pid1);
pid1=fork();
printf("current process if:%u\n",pid1);
printf("present pid value%u\n",pid1);
if(pid1==0)
{
printf("I am the child:%u%u\n",pid1,getpid());
pid1=getpid();
if(pid1==getpid())
printf("\n I am always executed by child process...child...");
}
else
{
printf("\n I am the parent:%u%u\n",pid1,getpid());
if(pid1==getpid())
printf("\n I am always executed by child process...parent...");
}
}
I am the parent:1313813137
[osb32@localhost osb32]$
RESULT:
Thus the program to implement system calls of UNIX operating system: fork,
exec, getpid, exit, wait, close, stat, opendir, readdir. was executed and verified
successfully.
AIM:
Algorithm
Step 5: Start with the first process from it’s initial position let other process to be in
queue
#include<stdio.h>
main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float att=0,awt=0;
for(i=0;i<10;i++)
{
a[i]=0; b[i]=0; w[i]=0; g[i]=0;
}
printf("enter the number of process");
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];
t[i]=g[i+1]-a[i];
awt=awt+w[i];
att=att+t[i];
}
awt =awt/n;
att=att/n;
printf("\n\tprocess\twaiting time\tturn arround time\n");
for(i=0;i<n;i++)
RESULT:
Thus the program to implement the First Come First Serve scheduling algorithm
executed successfully.
Aim
Algorithm
Step 4: Select the process which have shortest burst will execute first
Step 5: If two process have same burst length then FCFS scheduling algorithm used
Step 7: Start with the first process from it’s selection as above and let other process to
be in queue
#include<stdio.h>
int main()
{
int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10],i;
float att=0,awt=0;
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
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];
temp1=p[i];
b[i]=b[j];
p[i]=p[j];
b[j]=temp;
p[j]=temp1;
}
RESULT:
Thus the program to implement the shortest job first scheduling algorithm
executed successfully.
Aim
Algorithm
Step8: Make the CPU scheduler goes around the ready queue allocating CPU to each
process for the time interval specified
Step9: Make the CPU scheduler picks the first process and sets time to interrupt after
quantum expired dispatches the process
Step10: If the process have burst less than the time quantum than the process release
the CPU
Step11: If the process have bust greater then time quantum then time will go off and
cause interrupt to OS and the process put into the tail of ready queue and the
schedule select next process
RESULT:
Thus the program to implement the round robin scheduling algorithm executed
successfully.
Aim:
To write a program to implement producer consumer problem using semaphore
variable.
Algorithm:
Step 1: Declare required variables and assign required values for variables.
Step 2: Declare producer, consumer, wait and signal functions.
Step 3: Producer function:
The Producer can produce any number of items still he/she has space to store
the item when he/she gets the signal.
#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1)
{
printf("\nENTER YOUR CHOICE\n");
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;
1.PRODUCER
2.CONSUMER
3.EXIT
RESULT:
Thus the program to implement producer consumer problem was created and
executed successfully.
Aim:
To write a program to implement memory management scheme using
segmentation.
Algorithm:
Step 1: Read the base address, number of segments size of each segment and
memory limit.
Step 2: If memory address is less than base address display “Invalid memory
limit”.
Step 3: Create a segment table with the segment memory and segment
address and display it.
Step 5: If the segment number and displacement is valid compute the real
address and display the same.
#include<stdio.h>
main()
{
int n,p,b[10],i,s,la,l[10];
char a[10];
printf("\n Enter the no.of segments:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter the limit:");
scanf("%d",&l[i]);
printf("\n Enter the base:");
scanf("%d",&b[i]);
}
printf("\n Index \t limit \t base \n");
for(i=1;i<=n;i++)
printf("%d \t %d \t %d \n",i,l[i],b[i]);
printf("\n Enter the no.of process:");
scanf("%d",&p);
for(i=1;i<=p;i++)
{
printf("\n Enter the process name:");
scanf("%s",&a);
printf("\n Enter the segment number:");
scanf("%d",&s);
printf("\n Enter the logical address:");
scanf("%d",&la);
if(s<=n)
{
if(la<=l[s])
printf("\n The process %s is filled into the segment %d",a,s);
RESULT:
Thus the program to implement memory management scheme-Segmentation was
created and executed successfully.
Aim:
To write a program to implement memory management scheme using paging.
Algorithm:
Step 3: Determine the number of frame available by dividing the physical memory by
framesize.
#include<stdio.h>
main()
{
int i,arr[100],pagetable[20],val,pageno,offset,phymem;
int framesize,noframes;
printf("\n Enter the size of physical memory");
scanf("%d",&phymem);
for(i=0;i<phymem;i++)
arr[i]=i;
printf("\n Enter the size of frame or page:");
scanf("%d",&framesize);
noframes=phymem/framesize;
printf("\n The no.of frames available are %d",noframes);
printf("\n Enter the pagetable \n");
for(i=0;i<noframes;i++)
scanf("%d",&pagetable[i]);
printf("\n Enter the pageno.");
scanf("%d",&pageno);
printf("\n Enter the offset");
scanf("%d",&offset);
val=(framesize*pagetable[pageno])+offset;
printf("\n The physical + offset address is %d \n",arr[val]);
}
RESULT:
Thus the program to implement memory management scheme-Paging was
created and executed successfully.
Aim:
To write a program to implement memory management scheme-I First fit.
Algorithm:
Step 4: Get the number of process and size of the process from the user.
#include<stdio.h>
struct process
{
int ps,flag;
}p[5];
struct hole
{
int size,alloc;
}h[5];
int main()
{
int i=0,j=0,n=0,np=0;
printf("\n\t\t First Fit \n\n");
printf("\n Enter the no.of holes");
scanf("%d",&n);
printf("\n\t Enter the size for %d holes",n);
for(i=0;i<n;i++)
{
printf("\n\t Enter the size for %d holes",i);
scanf("%d",&h[i].size);
}
printf("\n\t Enter the no.of process");
scanf("%d",&np);
printf("\n\t\t Enter the size of %d process",np);
printf("\n");
for(i=0;i<np;i++)
{
printf("\n Enter the size of the process %d",i);
scanf("%d",&p[i].ps);
}
printf("\n Allocation of holes using first fit is as follows\n");
First Fit
First Fit
[osb32@localhost osb32]$
RESULT:
Thus the program to implement first fit memory management scheme was
created and executed successfully.