Professional Documents
Culture Documents
Ios Record
Ios Record
A
IILUSTRATE UNIX COMMANDS
Date:
i)cat
The cat command is considered as one of the most frequently used commands on
Linux. It can be used for the following purposes under UNIX or Linux
Syntax
Display text files on screen - cat filename
Combine text files - cat file1 file2
Create the file - cat > filename
Display file with line number - cat –n filename
iv)cd - Change directories. cd allows you to go to another directory, and thus, change your
current directory.
Syntax-cd path
v) ls - Lists the contents of the current directory. –l option is for long listing. -more
command is used to view page by page.
Syntax-ls directory name
vi) pwd-The pwd command (print working directory) is used to output the path of the
current working directory.
Syntax-pwd
vii) echo-echo command is used to send the output to file or a terminal.In this case, it
combines and print two strings
Syntax-echo hi
viii)cut-Cut command in unix (or linux) is used to select sections of text from each line of
files. You can use the cut command to select fields or columns from a line by specifying a
delimiter or you can select a portion of text by specifying the range or characters. Basically
the cut command slices a line and extracts the text
Syntax- cut –c1-2 filename
xi) cal command prints calendar of the given month or year. If the user does not specify any
command-line options, cal will print a calendar of the current month.
Syntax-cal month year
xii) sort-sort is a command that prints the lines of its input or concatenation of all files listed
in its argument list in sorted order. Sorting is done based on one or more sort keys extracted
from each line of input. By default, the entire input is taken as sort key. The "-r" flag will
reverse the sort order.
xiv) wc- is short for Word count. With various options turned on, you can count number or
bytes, characters, words, or lines from a file or standard input.
Syntax
wc -l <filename> print the line count
wc -c <filename> print the byte count
wc -m <filename> print the character count
wc -L <filename> print the length of longest line
wc -w <filename> print the word count
Syntax- top
xvii)Uniq- prints the unique lines in a sorted file, retaining only one of a run of matching
lines. Optionally, it can show only lines that appear exactly once, or lines that appear more
than once. uniq requires sorted input since it compares only consecutive lines.
Syntax- uniq –u ,uniq –d
xviii) cmp-Compares two files and tells you what line numbers are different
Syntax-cmp filename1 filename2
xix) who- displays a list of users who are currently logged into a computer. who am i
displays information about the current user only.
Syntax-who
Result:
Hence the aim,algorithm and output for unix commands is verified and executed
successfully.
Algorithm:
Step 1: Start
Step 2: Read the number
Step 3: If modulus value of the number by 2 equals 0, print Number is Even, else print
Number is odd.
Step 4: Stop
Program:
echo "Enter the Number"
read a
b=`echo "$a % 2"|bc`
if [ $b -eq 0 ]
then
echo "Given Number is Even "
exit
fi
echo " Given Number is odd"
Output:
2.Write a shell program to find the sum and average of four integers
Algorithm:
Step 1: Start
Step 2: Read a , b , c , d
Step 3: Add a,b,c,d and store in sum.
Step 4: Find average for a,b,c,d and store in avg
Step 5: Display sum and avg
Step 6: Stop
Program:
echo Enter four integers with space between
read a b c d
sum=`expr $a + $b + $c + $d`
avg=`expr $sum / 4`
Algorithm:
Step1: start
Step2: read p,n,r
Step3: calculate simple interest for p,n,r and store in S.I
Step4: display S.I
Step5: stop
Program:
echo " Enter the principle value: "
read p
echo " Enter the rate of interest:"
read r
echo " Enter the time period:"
read n
s=`expr $p \* $n \* $r / 100`
echo " The simple interest is "
echo $s
Output:
Algorithm:
Step1: Start
Step2: Read x ,y
Step3: Swap the values of x and y with help of a temporary variable ‘z’
Step4: Display the swapped values of x and y
Step5: Stop
Program:
Output:
Output:
Algorithm
Step 1: Start
Step 2: Read the value of quadratic equation constants a,b,c
7.Write a shell program to check whether the given number is positive or negative.
Algorithm:
Step 1: Start
Step 2: Read a number n
Step 3: if n is greater than 0
Step 4: Display the result as positive number
Step 5: else display the result as negative number
Step 6: Stop.
Program:
echo "Enter the number:"
read n
if [ $n -gt 0 ]
then
echo $n "is positive"
elif [ $n -lt 0 ]
then
echo $n "is negative"
else
echo $n "is zero"
fi
Output:
Program:
sum=0
for((i = 50 ; i<= 100 ; i++))
do
if [ `expr $i % 3` -eq 0 -a `expr $i % 5` -ne 0 ]
then
sum=`expr $sum + $i`
fi
done
echo $sum
Output:
Program:
for((i = 2020 ; i<= 2040 ; i++))
do if [ `expr $i % 400` = 0 ]
then echo "$i is a leap year"
elif [ `expr $i % 4` = 0 -a `expr $i % 100` != 0 ]
then echo "$i is a leap year"
fi
done
Output :
12.Write a Shell program to check the given number and its reverse are same
Algorithm:
Step 1: Start
Step 2: Read the number,n
Step 3: Repeat Until n value is greater than 0
i.Take n modulo 10 to extract the last digit from n
ii.use a temporary sum variable s which multiplies it’s content with 10,added with r
value.This is done to reverse the place value of digits.
iii.Divide n by 10 to ignore the final digit
Step 4: If s value is equal to input,print the number and it’s reverse are same,else print they
are not same
Step 5: Stop
Program:
echo "Enter a number:"
read n
t=$n
s=0
while [ $n -gt 0 ]
do
Output:
Program:
echo "Enter the number:"
read x
i=1
f=1
while [ $i -le $x ]
do
f=`expr $f \* $i`
i=`expr $i + 1`
c=`expr $i - 1`
done
echo "Factorial value is:" $f
Output:
16.Write a Shell program to check the given integer is Armstrong number or not
Algorithm
Step 1: Start
Step 2: Read the number,n
Step 3: Repeat Until n value is greater than 0
i.Take n modulo 10 to extract the last digit from n
ii.use a sum variable s which adds it’s content with cubic value of r each time
iii.Divide n by 10 to ignore the final digit
Step 4: If s value is equal to input,print the number is an amstrong number,else is not an
armstrong number
Step 5: Stop
Program:
echo "Enter a number:"
read n
t=$n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s + $r \* $r \* $r`
n=`expr $n / 10`
done
if [ $s = $t ]
then
echo "$t is an armstrong number"
else
Output:
Program:
19.Write a Shell program to execute various UNIX commands using case statements
Algorithm
Step 1: Start
Step 2: Display the options to execute different unix commands
Step 3: Get the choice from user
Step 4: Use a case statement that executes different commands based on choice given
Step 5: Stop
Program:
Output:
Program:
clear
echo -n "Enter the Name / String:"
while :
do
read name
echo $name | awk '{print gsub(/[aeiou]/,"")}'
done
Output:
Algorithm
Step 1:Start the program.
Step 2:Read the number
Step 3:Create a function add()
Step 4:Compute the addition value of A&B
Step 5:Cal the of function add()
Step 6:Stop the Program
Program:
Output:
Result:
Hence the aim,algorithm and output for shell programming is verified and executed
successfully.
Aim :
To write C programs for the fork, exec, getpid, exit, wait, close,stat, opendir, readdir
system calls of UNIX operating system.
Algorithm:
1. Include necessary header files for using systems calls.
2. Make necessary declaration.
3. Get the process identification number and parent process identification number using
getpid() and getppid() system calls
4. Display the process id’s
Program:
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
main()
{
int pid,ppid;
pid=getpid();
ppid=getppid();
printf("\n Process Id is %d\n",pid);
printf("\n Parent Process Id is %d\n",ppid);
}
Output:
Output:
Program:
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
int main()
{
int pid,i=0;
printf("\n Ready to fork");
pid=fork();
if(pid==0)
{
printf("\n Child starts ");
for(i=0;i <1000;i++);
printf("\n Child ends ");
}
else
{
wait(0); for(i=0;i<1000;i++);
Output:
Output:
Result:
Hence the aim,algorithm and output for unix and shell programming is verified and
executed successfully.
Aim:
To schedule snapshot of processes queued according to FCFS (First Come First
Serve)
Algorithm:
Program:
#include<stdio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);
printf("\nEnter Process Burst Time");
for(i=0;i<n;i++)
{
printf("\nP[%d]:",i+1);
scanf("%d",&bt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
Output:
Result:
Hence the aim,algorithm and output for FCFS scheduling is verified and executed
successfully.
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(ptime[i]>ptime[j])
{
temp = ptime[i];
ptime[i] = ptime[j];
ptime[j] = temp;
ptemp = process[i];
process[i] = process[j];
process[j] = ptemp;
} }}
wtime[0]=0;
Output:
Result:
Hence the aim,algorithm and output for SJF scheduling is verified and executed
successfully.
Aim :
To schedule snapshot of processes queued according to Priority scheduling.
Algorithm :
1. Get length of the ready queue, i.e., number of process (say n)
2. Obtain btime and pri for each process.
3. Sort the processes according to their pri in ascending order.
a. If two process have same pri, then FCFS is used to resolve the tie.
4. The wtime for first process is 0.
5. Compute wtime and ttime for each process as:
a. wtimei+1 = wtimei + btimei
b. ttimei = wtimei + btimei
6. Compute average waiting time awat and average turn around time atur
7. Display the btime, pri, ttime and wtime for each process.
8. Display awat and atur
9. Stop
Program:
#include<stdio.h>
void main()
{
int burst[10],pid[10],priority[10],wt[10],total, n, i, j, temp;
printf("\nPriority Scheduling");
printf("\nEnter Number of Processes:");
scanf("%d",&n);
printf("\nEnter %d Processes Details\n\n",n);
for(i=0;i<n;i++)
{
printf("\nEnter Process %d ID:",i+1);
scanf("%d",&pid[i]);
printf("\nEnter Process %d Burst Time:",i+1);
scanf("%d",&burst[i]);
printf("\nEnter Process %d Priority:",i+1);
scanf("%d",&priority[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(priority[i]<priority[j])
{
//Swapping Processes Based on Priority
temp=priority[i];
priority[i]=priority[j];
priority[j]=temp;
Output:
Result:
Hence the aim,algorithm and output for priority scheduling is verified and executed
successfully.
Aim :
To schedule snapshot of processes queued according to Round robin scheduling.
Algorithm :
1. Get length of the ready queue, i.e., number of process (say n)
2. Obtain Arrrival time at Burst time bt for each processes Pi.
3. Get the time slice per round, say ts
4. Determine the number of rounds for each process.
5. The wait time for first process is 0.
6. If bt > ts then process takes more than one round. Therefore turnaround and
waiting time should include the time spent for other remaining processes in the
same round.
7. Calculate average waiting time and turnaround time
8. Display the burst time, turnaround time and wait time for each process (in order
of
rounds they were processed).
9. Display average wait time and turnaround time
10. 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];
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
scanf("%d",&time_quantum);
for(time=0,count=0;remain!=0;)
time+=rt[count];
rt[count]=0;
flag=1;
else if(rt[count]>0)
rt[count]-=time_quantum;
time+=time_quantum;
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
if(count==n-1)
count=0;
count++;
else
count=0;
return 0;
Output:
Program 40
Output 20
Result 10
Viva voce 10
Result:
Hence the aim , algorithm and output for the cpu scheduling round robin is verified
and executed successfully.
Aim :
To write a C Program to implement interprocess communication using shared memory.
Algorithm :
smserver.c
1. Start the program.
2. Declare the variables – shmid, key, size.
3. Assign a value for the variable ‘key’.
4. Create a shared memory segment (of size 27 bytes) and obtain access to it.
5. Attach the segment to the data space.
6. Write user input data directly to the segment.
7. Wait until the other process reads the segment and changes the first character of memory as
‘*’.
8. Stop the program
smclient.c
1. Start the program.
2. Declare the variables – shmid, key, size.
3. Assign a value for the variable ‘key’.
4. Locate the segment created by server.
5. Attach the segment to the data space.
6. Read the data available in the shared memory segment.
7. After reading, change the first character as ‘*’, to indicate the segment has been read.
8. Stop the program.
Program:
smserver.c
#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdlib.h>
#define SHMSIZE 27
int main()
{
char data;
int shmid,i;
key_t key;
char *shm,*s;
{
perror("shmget got failed");
exit(1);
}
if((shm=shmat(shmid,NULL,0))==(char *) -1)
{
perror("shmat got failed");
exit(1);
}
s=shm;
for(i=0;i<60;i++){
scanf("%c",&data);
*s++=data;
*s=NULL;
}
while(*shm != '*')
sleep(1);
exit(0);
}
smclient.c
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/types.h>
#include<stdlib.h>
#define SHMSIZE 27
main()
}
if((shm=shmat(shmid,NULL,0))==(char*)-1)
{
perror("shmat");
exit(1);
}
for(s=shm;*s!= NULL;s++)
putchar(*s);
putchar('\n');
*shm='*';
exit(0);
}
Result :
The program for inter process communication using shared memory was implemented
and verified successfully.
Aim :
To implement producer and consumer problem using semaphore variable.
Algorithm :
Program:
#include <stdio.h>
#include <string.h>
#define size 5
struct process
{
char item[10];
}p[10];
int flag=0, full=0, empty=size, mutex=1;
int wait(int s)
{
if(s==0)
flag=1;
else
s--;
return s;
}
return s;
}
main()
{
int c, i;
printf("\nProducer-Consumer Problem\n");
while(1)
{
printf("\n1.Produce 2.Consume 3.Display 4.Exit\n");
printf("Enter your choice : ");
scanf("%d", &c);
switch(c)
{
case 1:
empty = wait(empty);
mutex = wait(mutex);
if(flag == 0)
{
printf("Enter the item to produce : ");
scanf("%s", p[full].item);
full = signal(full);
}
else
{
printf("\nBuffer is FULL\n");
flag = 0;
case 2:
full = wait(full);
mutex = wait(mutex);
if(flag == 0)
{
printf("Item %s is consumed\n",p[0].item);
for(i=0; i<size; i++)
strcpy(p[i].item, p[i+1].item);
flag=0;
}
else
{
printf("\nBuffer is EMPTY\n");
flag = 0;
}
mutex = signal(mutex);
empty = signal(empty);
break;
case 3:
if(full != 0)
{
printf("\nItems in the buffer : ");
for(i=0; i<full; i++)
printf("\n%s", p[i].item);
}
else
}
break;
case 4:
exit(0);
break;
}
}
}
Output:
Program 40
Output 20
Result 10
Viva voce 10
Result:
Thus the Implementation of producer and consumer problem using semaphore done
successfully.
Aim :
To write a C program to implement the banker’s algorithm for deadlock avoidance.
Algorithm :
1. Start the program.
2. Declare the variables for processes, maximum, allocation, available, completed,
safe sequence matrices.
3. Get the number of processes, resources and their instances.
4. Get the maximum, allocation and available matrices for all processes.
i. Step 5: Calculate the need matrix for all process, and initialize the
completed matrix as ‘0’.
5. Repeat steps from 7 to 10, for all process till they complete.
6. Print the allocation and max matrix for all process.
7. For all process, such that completed[p]=0 then go to step 8 else step 9.
8. If available is less than need, break.
9. For the process,i
1. calculate available=available+allocation
2. allocation=0, max=0
3. add the process to safe sequence matrix
4. add this process to completed matrix
10. If all processes are completed print “system in safe state” and also print safe
sequence list, else print “system is not in safe state”.
11. End the program.
Program:
#include <stdio.h>
#include <stdlib.h>
int main() {
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10],
safeSequence[10];
int p, r, i, j, process, count;
count = 1;
printf("Enter the no of processes : ");
scanf("%d", &p);
Output:
Program 40
Output 20
Result 10
Viva voce 10
Result:
Thus the implementation of banker’s algorithm for deadlock avoidance is executed and
verified successfully.
Aim :
To write a C program to simulate an algorithm for Dead Lock detection.
Algorithm :
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail, allocation and need matrices.
4. for all process make finish as 0.
5. for all processes
a) If finish=0 and need<work then
i. work += allocation
ii. finish =1;
iii. set flag=1;
6. For all processes
7. If finish =0 then add to dead matrix
8. If flag =1 else go to step 8
9. Print System is in deadlock.
10. for all processes
i. i)If finish=0 and flag=1 then print the process name as deadlock
11. creating process
12. Print system is not in deadlock.
13. end
Program:
#include<stdio.h>
#include<conio.h>
int alloc[10][10];
int need[10][10];
int avail[10];
int n,r;
void input();
void show();
void deadlock_detect();
int main()
{
int i,j;
printf("********** Deadlock Detection Algorithm ************\n");
input();
show();
deadlock_detect();
getch();
return 0;
}
void input()
Output:
Result:
Thus the implementation of deadlock detection algorithm is executed and verified
successfully.
Aim:
To write a c program for the implementation of threading
Algorithm:
1. Start Program
2. Initialize thread id of type pthread_t
3. Initialize counter
4. Create number of threads using pthread_create
5. Call the function that is defined to use thread
6. Check the synchronization of threads using pthread_join
7. Stop the program
Program :
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
pthread_t tid[2];
int counter;
void* doThings(void *arg)
{
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n", counter);
return NULL;
}
main()
{
int i = 0;
int err;
Result:
Implementation of Threading and Synchronization of thread done sucessfully.
Aim:
To implement the c program for the paging technique
Algorithm:
1.Initialize System Parameters: Input total memory size and page size, then calculate the
number of pages in memory.
2.Input Process Information and Allocate Pages: Input the number of processes, and for each
process, input the required number of pages and allocate them if sufficient memory is
available.
3.Create Page Tables for Each Process: For each process, input the frame numbers to create
its page table.
4.Translate Logical Address to Physical Address: Input the process number, page number,
and offset, then validate the inputs.
5.Output the Physical Address: Calculate the physical address using the page table and
display it if inputs are valid, otherwise display an error message.
Program:
#include <stdio.h>
int main() {
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
int s[10], fno[10][20];
printf("\nEnter the memory size -- ");
scanf("%d", &ms);
printf("\nEnter the page size -- ");
scanf("%d", &ps);
nop = ms / ps;
printf("\nThe number of pages available in memory are -- %d", nop);
printf("\nEnter number of processes -- ");
scanf("%d", &np);
rempages = nop;
rempages -= s[i];
printf("\nEnter page table for p[%d] --- ", i);
return 0;
}
Result:
Hence the aim , algorithm and output for the implementation for the paging techmique
is verified and executed successfully.
Aim:
To implement the c program for the memory allocation method first fit.
Algorithm:
1. Initialization:Maintain a list of free memory blocks and processes with their memory
requirements.
2. Process Request:For each process that needs memory, determine its memory
requirement.
3. Search for Free Block:Traverse the list of free memory blocks from the beginning and
find the first block that is large enough.
4. Allocate Memory:Allocate the found memory block to the process, adjust the block
size or remove it if fully used, and mark the process as allocated.
5. Handle Allocation Failure:If no suitable block is found, mark the process as not
allocated and handle it according to system policy.
Program:
#include<stdio.h>
void main()
flags[i] = 0;
allocation[i] = -1;
scanf("%d", &bno);
scanf("%d", &bsize[i]);
scanf("%d", &pno);
allocation[j] = i;
flags[j] = 1;
break;
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
Result:
Hence the aim , algorithm and output for the implementation for the memory
allocation method first fit is verified and executed successfully.
Aim:
To implement the c program for the memory allocation method worst fit
Algorithm:
1. Initialize:Mark all memory blocks as free,Set all process allocations to unallocated.
2. Input:Read the number of memory blocks and their sizes,Read the number of
processes and their sizes.
3. Allocate Memory:For each process:
4. Search: Find the largest free memory block that can accommodate the process.
5. Allocate:If such a block is found:Allocate the process to this block.
6. Mark this block as occupied or reduce the block size by the size of the allocated
process.
7. If no suitable block is found, the process remains unallocated.
8. Output:For each memory block, display the block number, its size, the process
allocated to it (if any), and the size of the allocated process.
Program:
#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
Result:
Hence the aim , algorithm and output for the implementation of memory allocation
method worst fit is verfired and executed successfully.
Aim:
To implement the c program for the memory allocation method best fit
Algorithm:
1. Initialize:Mark all memory blocks as free.Set all process allocations to unallocated.
2. Input:Read the number of memory blocks and their sizes.Read the number of
processes and their sizes.
3. Allocate Memory:For each process it wil Search and find the smallest free memory
block that is large enough to accommodate the process.
4. Allocate:If such a block is found then allocate the process to this block and mark this
block as occupied.
5. Calculate and record the fragmentation (unused memory) in the block after
allocation.If no suitable block is found, the process remains unallocated.
6. Output:For each memory block, display the block number, its size, the process
allocated to it (if any), and the fragmentation.
Program:
#include<stdio.h>
#include<conio.h>
#define max 30
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
Result:
Hence the aim , algorithm and output for the implementation of memory allocation
method best fit is verfired and executed successfully.
Aim:
To implement the c program for the page replacement algorithm FIFO(First in First Out)
Algorithm:
Step 1: Start the program
Step 2: Declare reference string, frame .
Step 3: Get the reference string and its length.
Step 4: Get the number of frames and initialize them as -1.
Step 5: For each page in reference string
a) If page is not available in the frame.
i) Increment page fault
ii) Replace the oldest page by this current page.
Step 6: Display the reference string, frame contents.
Step 7: Stop the program.
Program:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
return 0;
}
Output:
Result:
Thus the implementation of replacement algorithm FIFO is executed and verified
successfully.
Algorithm:
1. Start the program.
2. Get the number of pages, reference string and number of frames.
3. Declare count variable.
4. Copy the first page to the first frame and increment page fault count.
5. For the remaining pages, select the least recently used page by counter value
6. Replace them accordingly to the selection.
7. Display the values.
8. Display the number of page faults.
9. Stop the program
Program:
#include <stdio.h>
int arrmin(int[], int);
int main()
{
int i,j,len,rs[50],frame[10],nf,k,avail,count=0;
int access[10], freq=0, dm;
printf("Length of Reference string : ");
scanf("%d", &len);
printf("Enter reference string :\n");
for(i=1; i<=len; i++)
scanf("%d", &rs[i]);
printf("Enter no. of frames : ");
scanf("%d", &nf);
for(i=0; i<nf; i++)
frame[i] = -1;
j = 0;
printf("\nRef. str Page frames");
for(i=1; i<=len; i++)
{
Result:
Thus the implementation of replacement algorithm LRU is executed and verified
successfully.
Algorithm:
1. Start the program.
2. Declare and initialize total_frames, total_pages, hit = 0
3. Get the input for number of pages and frames
4. Set frame[]=-1 for all frames and count[]=0 for all pages.
5. Get the input for pages.
6. For each page in reference string repeat steps from 7 to 13
7. Increment the count for the page
8. Set the time for the page
9. Set flag to 1.
10. Set least to initial frame.
11. For each frame
If frame is either not empty or filled with current page then
If frame is not empty then
Increment hit and decrement pgfault
Set flag to 0
load frame with the current page
Compare the count of least and current frame and set least to the minimum
12.If flag is set to 1 then
Set mintime to 50
For each frame
If count of current frame is equal to least and time of current frame is less than mintime
Set temp as j
Set mintime as time[frame[]]
Set count for the new frame to 0
Load the page in to new frame
13. For each frames
Print frame[]
14. Print the hit and pagefault.
15. Stop the program.
Program:
#include<stdio.h>
int main()
{
int total_frames, total_pages, hit = 0;
int pages[25], frame[10], arr[25], time[25];
int m, n, page, flag, k, minimum_time, temp;
Result:
Thus the implementation of replacement algorithms LFU is executed and verified
successfully.
Aim:
To implement the file organization technique single level directory structure
Algorithm:
1. Start the program.
2. Get the number of directories,names of dorectories
3. Get the size of directories and file names.
4. Display the directory names,size of directory and files under the directory
5. Stop the program
Program:
#include<stdio.h>
main()
{
int totaldir,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
printf("enter number of directories:");
scanf("%d",&totaldir);
printf("enter names of directories:");
for(i=0;i<totaldir;i++)
scanf("%s",&d[i]);
printf("enter size of directories:");
for(i=0;i<totaldir;i++)
scanf("%d",&s[i]);
printf("enter the file names :");
for(i=0;i<totaldir;i++)
for(j=0;j<s[i];j++)
scanf("%s",&f[i][j]);
printf("\n");
printf(" DIRECTORIES\tSIZE\tFILE NAMES\n");
printf("*************************************************\n");
for(i=0;i<totaldir;i++)
{
printf("%s\t\t%2d\t",d[i],s[i]);
for(j=0;j<s[i];j++)
printf("%s\n\t\t\t",f[i][j]);
printf("\n");
}
printf("\t\n");}
Result:
Hence the aim , algorithm and output for the file organization technique single level
structure is verified and executed successfully
Aim:
To implement the file organization technique two level directory structure
Algorithm:
1. Start the program.
2. Define a structure to get directory names,sub directory names and file names
3. Get the number of directories,names of directories and size of directories
4. Get the sub directories name and size
5. Get the file names under sub directories
6. Display the directory names,size of directory and name of the file under sub
directories
7. Stop the program.
Program:
#include<stdio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
void main()
{
int i,j,k,n;
printf("enter number of directories:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d name:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directory:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("enter file name:");
scanf("%s",&dir[i].fname[j][k]);
}
}
}
printf("\nDIRNAME\t\tSIZE\tSUB DIR. NAME\tSIZE\tFILES");
printf("\n******************************************************\n");
Aim:
To implement the file organization technique hierarchial directory structure
Algorithm:
1. Start the process.
2. Create root directrory of directory structure
3. Show the user options
1. Create directory under root.
2. Create directory under a directory
3. Create file under root directory.
4. Create file under directory.
4. Get the choice from user
1. Create directrory under root.
1. Call the createdirectory fuction with root directory.
2. Return directory.
2. Create directory under some directory.
1. Check the home directory that the user want create directory is preset or not
2. if directory found create directory under found
3. else print error message
3. Create file under root.
1. Call the createdirectory fuction with root directory.
2. Return file.
4. Create file under some directory.
Check the home directory that the user want create directory is
1. preset or not
2. if directory found create file under found
3. else print error message
5. repeat loop until user want to exit.
6. Stop the process.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct directory *hit;
//STRUCTE OF FILE
typedef struct file{
char f_name[20];
struct dir *home;
root=create_root();
char name[20];
int choice;
do
{
printf("\n1.Create Directroy under ROOT\n2.Create directory under other
directory"
"\n3.Create file under ROOT\n4.Create file under other
directory\n5.EXIT");
Result:
Hence the aim , algorithm and output fro the file organization technique hireachial
structure is verified and executed successfully.
Aim :
To implement file allocation on free disk space in a contiguous manner.
Algorithm :
1. Start the program
2. Get the no of files,no of blocks occufied by files and starting block of files
3. Display file name, start block and length
4. Display blocks occupied by the no of files
5. Stop program
Program:
#include<stdio.h>
main()
{
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
printf("Enter no.of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter no. of blocks occupied by file%d",i+1);
scanf("%d",&b[i]);
printf("Enter the starting block of file%d",i+1);
scanf("%d",&sb[i]);
t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
}
printf("Filename\tStart block\tlength\n");
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
printf("blocks occupied are:\n");
for(i=0;i<n;i++)
{ printf("file no %d",i+1);
for(j=0;j<b[i];j++)
printf("\t%d",c[i][j]);
printf("\n");
}
}
Result :
Thus sequential allocation is done for files with the available free blocks.
Aim :
To implement file allocation on free disk space using indexed file allocation method.
Algorithm :
Program:
#include<stdio.h>
main()
{
int n,m[20],i,j,ib[20],b[20][20];
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Enter index block :",i+1);
scanf("%d",&ib[i]);
printf("Enter blocks occupied by file%d:",i+1);
scanf("%d",&m[i]);
printf("enter blocks of file%d:",i+1);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
} printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\n",i+1,ib[i],m[i]);
printf("blocks occupied are:\n");
for(i=0;i<n;i++)
{ printf("fileno%d",i+1);
for(j=0;j<m[i];j++)
printf("\t%d--->%d\n",ib[i],b[i][j]);
printf("\n");
}
}
Result
Thus indexed file allocation is done for files with the available free blocks.
Aim :
To implement file allocation on free disk space in a linked file memory allocation
manner.
Algorithm :
Program
#include<stdio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
main()
{
int i,j,n;
printf("Enter no. of files:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&f[i].fname);
printf("Enter starting block:");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("Enter no.of blocks:");
scanf("%d",&f[i].size);
printf("Enter block numbers:");
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=0;j<f[i].size;j++)
Output:
Result :
Thus Linked file allocation is done for files with the available free blocks.
Aim :
1. Initialize:Read the initial position of the disk head,Read the sequence of disk requests.
2. Process Requests:Serve the disk requests in the order they arrive, one by one.
3. Calculate Metrics:For each request, calculate the distance (seek time) the disk head moves
from its current position to the position of the next request,Keep a running total of the seek
times tcalculate the total seek time.
4. Output:Display the order in which the disk requests were served,Display the total seek
time.
PROGRAM :
#include <stdio.h>
#include <stdlib.h>
void FCFS(int requests[], int n, int head) {
int seek_count = 0;
int distance, cur_track;
printf("Seek Sequence is:\n");
for (int i = 0; i < n; i++) {
cur_track = requests[i];
printf("%d ", cur_track);
distance = abs(cur_track - head);
// Increase the total count
seek_count += distance;
head = cur_track;
}
printf("\nTotal number of seek operations = %d\n", seek_count);
}
int main() {
int n, head;
Result:
Hence the aim , algorithm and output for disk scheduling algorithm FCFS is verified and
executed successfully.
Aim :
Result:
Hence the aim , algorithm and output for disk scheduling SSTF algorithm is verified and
executed successful
Aim :
To write a C program for implementing disk scheduling algorithm scan scheduling algorithm
Algorithm:
1. Initialize:Read the initial position of the disk head.Read the sequence of disk
requests.Read the direction of the initial movement (towards the start or end of the
disk).
2. Sort Requests:Sort the requests in ascending order of their positions.
3. Process Requests:If the initial direction is towards the end of the disk:Service all
requests from the current position to the end of the disk in order.Reverse direction at
the end of the disk.
4. Service all remaining requests from the end of the disk back towards the start.
5. If the initial direction is towards the start of the disk:Service all requests from the
current position to the start of the disk in order.
6. Reverse direction at the start of the disk.
7. Service all remaining requests from the start of the disk back towards the end.
8. Calculate Metrics:For each request, calculate the distance (seek time) the disk head
moves.
9. Keep a running total of the seek times to calculate the total seek time.
10. Output:Display the order in which the disk requests were served.
11. Display the total seek time.
Program:
#include <stdio.h>
#include <stdlib.h>
void SCAN(int requests[], int n, int head, int direction) {
int seek_count = 0;
int distance, cur_track;
int size = 200; // size of the disk
int *seek_sequence = (int *)malloc((n + 2) * sizeof(int));
int index = 0;
printf("Seek Sequence is:\n");
if (direction == 1) { // Move towards the end
for (int i = 0; i < n; i++) {
Result:
Hence the aim , algorithm and output for disk scheduling scan algorithm is verified and executed
successful
Aim :
To write a C program for implementing disk scheduling algorithm scan scheduling algorithm
Algorithm:
1. Initialize:Read the initial position of the disk head.Read the sequence of disk
requests.Assume the direction is always towards the end of the disk for servicing.
2. Sort Requests:Sort the requests in ascending order of their positions.
3. Process Requests:Service all requests from the current position to the end of the disk
in order.
4. Jump to the start of the disk without servicing any requests.
5. Service all remaining requests from the start of the disk to the initial position in
ascending order.
6. Calculate Metrics:For each request, calculate the distance (seek time) the disk head
moves.Keep a running total of the seek times to calculate the total seek time.
7. Output:Display the order in which the disk requests were served.Display the total seek
time.
Program:
#include <stdio.h>
#include <stdlib.h>
void CSCAN(int requests[], int n, int head) {
int seek_count = 0;
int distance, cur_track;
int size = 200; // size of the disk
int *seek_sequence = (int *)malloc((n + 2) * sizeof(int));
int index = 0;
Output:
Result:
Hence the aim , algorithm and output for disk scheduling c scan algorithm is verified and
executed successful
AIM:
To Install Virtual Box/VMware Workstation with different flavours of Linux or Windows OS
on top of windows7 or 8
PROCEDURE:
Install Ubuntu as the guest operating system from an ISO image file. To create a new virtual
machine click on the New button in the Virtual Box Manager GUI window.
Give the VM a name and make sure that the operating system and version are Linux and
Ubuntu, respectively. Click Next.
Next, you must specify a virtual hard disk for your VM. There are multiple ways in which
Virtual Box can provide hard disk space to a VM, but the most common way is to use a large
image file on your real hard disk, whose contents Virtual Box presents to your VM as if it were
a complete hard disk. This file represents an entire hard disk then, so you can even copy it to
another host and use it with another Virtual Box installation:
Next, type the name of the new virtual hard drive file or select a different folder to create the
file in and click Create:
Next, click Storage in the left pane and click the CD icon in the right pane to browse for the
Ubuntu ISO you downloaded in the first steps.
Click OK to close Settings and then start your new Ubuntu VM by clicking the green Start
arrow in the main Virtual Box window.
After a few seconds the Ubuntu welcome window happily shoots on the screen ready to install
Ubuntu.
3. At this point, choose the installation type and the first screenshot is an automated process,
even if you have an operating system already installed, the installer will auto-detect it and allow
you partition the drive in the next screen with simple sliders that will auto-allocate your
assigned space for the Ubuntu partition.
4. Prompt to confirm that you want the changes to be made to your internal drive; click continue
to move onto the next screen.
7. This is where you enter your user details and clicks continue to proceed to the next screen.
8. Right up next, is the beginning of installation which (depending on your PC hardware), can
take a long or short time.
9. At this point, the installation is complete and now, you may restart your PC.
10. Once you’ve restarted, you are now greeted with the login screen where you input your
password.
RESULT:
Thus, the Virtual Box/VMware Workstation with different flavors of Linux or Windows OS
has been successfully installed.