Wednesday, 20 March 2024

FCFS Disk Scheduling algorithm

//I) Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122, 14, 124, 65, 67. The head is initially at cylinder number 53 moving towards larger cylinder numbers on its servicing pass. The cylinders are numbered from 0 to 199.
//Write an OS program to implement FCFS Disk Scheduling algorithm to calculate the total head movement (in number of cylinders).
//Solution:
#include<stdio.h>
int front,rear;
void init()
{
front=rear=-1;
}
void display(int *Q)
{
int i;
for(i=front;i<=rear;i++)
printf("\t%d",Q[i]);
}
void enqueu(int *Q,int n,int var)
{
if(rear==n)
printf("\nQueue is Full");
else
{
if(front==-1)
front++;
rear++;
Q[rear]=var;
}
}
int FCFS(int *Q, int n)
{
    int j,seek=0,diff;
    for(j=0;j<n;j++)
    {
        diff=abs(Q[j+1]-Q[j]);
        seek+=diff;
    printf("Disk head moves from %d to %d with seek %d\n",Q[j],Q[j+1],diff);
    }
    return seek;
}
int main()
{
    int queue[20],n,var,head,i,j,k,seek,max;
    float avg;
    init();
   // printf("\nFront=%d\nRear=%d",front,rear);
    printf("\nEnter the max range of disk\n");
    scanf("%d",&max);
    printf("Enter the size of queue request\n");
    scanf("%d",&n);
    printf("Enter the initial head position\n");
    scanf("%d",&head);
    printf("Enter the queue of disk positions to be read\n");
    enqueu(queue,n,head);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&var);
        if(var<0||var>max)
            printf("\nError..!Given Position is invalid\n");
        else
        {
            enqueu(queue,n,var);
        }
    }
    printf("\nGiven Queue is\n");
    display(queue);
    printf("\n\nFCFS Algorithm\n");
    seek=FCFS(queue,n);
    printf("Total seek time is %d\n",seek);
    avg=seek/(float)n;
    printf("Average seek time is %f\n",avg);
    return 0;
}

Saturday, 7 January 2023

Python Programming Laboratory

 

Python Programming Laboratory

Savitribai Phule Pune University, 
M.Sc. (Computer Application) (Semester-III) Practical Examination Solved Slips.

Wednesday, 26 January 2022

OS-(I) Assignment 4: Demand Paging and Page Replacement Algorithms

Demand Paging


NEW.

Set A.

(1) Write the simulation program to implement demand paging and show the page scheduling and total number of page faults for the following given page reference string. Give input n as the number of memory frames.
Reference String : 12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8
1) Implement FIFO 
2) Implement LRU.


Set B.

(1)Write the simulation program to implement demand paging and show the page scheduling and total number of page faults for the following given page reference string. Give input n as the number of memory frames.
Reference String : 12,15,12,18,6,8,11,12,19,12,6,8,12,15,19,8
1) Implement OPT
2) Implement MFU.

OS-(I) Assignment 3: CPU Scheduling Algorithms

CPU Scheduling


Set A.

(1)Write the program to simulate FCFS CPU-scheduling. The arrival time and first CPU- burst for different n number of processes should be input to the algorithm. Assume that the fixed IO waiting time (2 units). The next CPU-burst should be generated randomly. The output should give Gantt chart, turnaround time and waiting time for each process. Also find the average waiting time and turnaround time..
 

Set B.

(1) Write the program to simulate Preemptive Shortest Job First (SJF) -scheduling. The arrival time and first CPU-burst for different n number of processes should be input to the algorithm. Assume the fixed IO waiting time (2 units). The next CPU-burst should be generated randomly. The output should give Gantt chart, turnaround time and waiting time for each process. Also find the average waiting time and turnaround time.
 
(2) Write the program to simulate Non-preemptive Priority scheduling. The arrival time and first CPU-burst and priority for different n number of processes should be input to the algorithm. Assume the fixed IO waiting time (2 units). The next CPU-burst should be generated randomly. The output should give Gantt chart, turnaround time and waiting time for each process. Also find the average waiting time and turnaround time.

OS-(I) Assignment 2: Simulation of Operating System Shell and Its Working

MyShell


Set A.

Write a C program that behaves like a shell which displays the command prompt ‘myshell$’. It accepts the command, tokenize the command line and execute it by creating the child process.Also implement the additional command ‘count’ as 
myshell$ count c filename: It will display the number of characters in given file 
myshell$ count w filename: It will display the number of words in given file 
myshell$ count l filename: It will display the number of lines in given file .


Set B.

Write a C program that behaves like a shell which displays the command prompt ‘myshell$’. It accepts the command, tokenize the command line and execute it by creating the child process. Also implement the additional command ‘list’ as
myshell$ list f dirname: It will display filenames in a given directory.
myshell$ list n dirname: It will count the number of entries in a given directory.
myshell$ list i dirname: It will display filenames and their inode number for the files in a given directory.


Set C.

1) Write a C program that behaves like a shell which displays the command prompt ‘myshell$’. It accepts the command, tokenize the command line and execute it by creating the child process. Also implement the additional command ‘typeline’ as
myshell$ typeline n filename: It will display first n lines of the file.
myshell$ typeline -n filename: It will display last n lines of the file.
myshell$ typeline a filename: It will display all the lines of the file.

2)Write a C program that behaves like a shell which displays the command prompt ‘myshell$’. It accepts the command, tokenize the command line and execute it by creating the child process.Also implement the additional command ‘search’ as
myshell$ search f filename pattern: It will search first occurrence of the pattern in the given file.
myshell$ search a filename pattern: It will search all occurrence of the pattern in the given file.
myshell$ search c filename pattern: It will count the number of occurrences of the pattern in the given file.