0% found this document useful (0 votes)
11 views21 pages

Program No 01

The document outlines the hardware and software requirements for various operating systems including UNIX, Linux, Windows XP, Windows 7, and Windows 8. It also includes programming implementations for CPU scheduling policies such as Shortest Job First (SJF), First-Come-First-Serve (FCFS), Priority, Round Robin, and Multi-level Queue. Additionally, it discusses memory allocation and internal fragmentation calculations.

Uploaded by

Harsh Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views21 pages

Program No 01

The document outlines the hardware and software requirements for various operating systems including UNIX, Linux, Windows XP, Windows 7, and Windows 8. It also includes programming implementations for CPU scheduling policies such as Shortest Job First (SJF), First-Come-First-Serve (FCFS), Priority, Round Robin, and Multi-level Queue. Additionally, it discusses memory allocation and internal fragmentation calculations.

Uploaded by

Harsh Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Ishita Sachan 2200911540057 CSDS-1 G2

PROGRAM NO 01
OBJECTIVE:- Study of hardware and so ware requirements of different opera ng systems
(UNIX,LINUX,WINDOWS XP,WINDOWS7/8).

UNIX

Hardware Requirements:
- Processor: Typically, UNIX systems can run on a wide range of processors, from early mainframes and
minicomputers to modern RISC and CISC architectures.
- Memory: UNIX systems have historically been designed to run on systems with as li le as 4 MB of RAM, but
modern implementa ons usually require more.
- Storage: Varies widely; early UNIX systems could run on 20 MB of disk space, while modern implementa ons need
significantly more.
- Network: Basic networking capabili es are o en built-in, with support for various network interfaces.
So ware Requirements:
- Kernel: UNIX kernel, which manages system resources.
- Shell: A command-line interface, like Bourne shell (sh), C shell (csh), or Korn shell (ksh).
- U li es: Standard UNIX u li es for file management, text processing, and programming.

Linux

Hardware Requirements:
- Processor: Intel x86 or compa ble, ARM, PowerPC, and more. Modern distribu ons support 64-bit processors.
- Memory: Minimum of 512 MB to 1 GB of RAM for lightweight distribu ons; 2 GB or more for standard desktop
distribu ons.
- Storage: Minimum of 5 GB for a basic installa on; 20 GB or more for a full-featured desktop environment.
- Graphics: VGA capable; modern distribu ons may require 3D accelera on for advanced desktop effects.
So ware Requirements:
- Kernel: Linux kernel, the core of the opera ng system.
- Shell: Bash (Bourne Again Shell) or other shells like Zsh, Fish.
- Desktop Environment: GNOME, KDE, XFCE, or others for graphical user interfaces.
- Package Manager: APT (Debian-based), YUM/DNF (Red Hat-based), or Pacman (Arch-based).

Windows XP

Hardware Requirements:
- Processor: Pen um 233 MHz or higher; recommended 300 MHz or higher.
- Memory: Minimum of 64 MB of RAM; recommended 128 MB or more.
- Storage: Minimum of 1.5 GB of available hard disk space.
- Graphics: Super VGA (800 x 600) or higher-resolu on video adapter and monitor.
So ware Requirements:
- Opera ng System: Windows XP installa on media.
Ishita Sachan 2200911540057 CSDS-1 G2
- Applica ons: Various third-party applica ons available; legacy support for older so ware.
- Drivers: Specific drivers for hardware components (graphics, network, sound, etc.).

Windows 7

Hardware Requirements:
- Processor: 1 GHz or faster 32-bit (x86) or 64-bit (x64) processor.
- Memory: 1 GB RAM (32-bit) or 2 GB RAM (64-bit).
- Storage: 16 GB available hard disk space (32-bit) or 20 GB (64-bit).
- Graphics: DirectX 9 graphics device with WDDM 1.0 or higher driver.
So ware Requirements:
- Opera ng System: Windows 7 installa on media.
- Applica ons: Compa bility with a wide range of so ware, including legacy Windows XP applica ons in XP Mode
(Professional, Ul mate, and Enterprise edi ons).
- Drivers: Specific drivers for hardware components; improved plug-and-play support.

Windows 8

Hardware Requirements:
- Processor: 1 GHz or faster processor with PAE, NX, and SSE2 support.
- Memory: 1 GB RAM (32-bit) or 2 GB RAM (64-bit).
- Storage: 16 GB available hard disk space (32-bit) or 20 GB (64-bit).
- Graphics: Microso DirectX 9 graphics device with WDDM driver.
So ware Requirements:
- Opera ng System: Windows 8 installa on media.
- Applica ons: Support for modern UI (formerly Metro) apps and tradi onal desktop applica ons.
- Drivers: Specific drivers for hardware components; enhanced touch and gesture support for touch-enabled
devices.
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 02
OBJECTIVE:- Implement CPU Scheduling Policies using SJF.
#include <stdio.h>
int main() {
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
prin ("Enter number of process: ");
scanf("%d", &n);
prin ("Enter Burst Time:\n");
for (i = 0; i < n; i++) {
prin ("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1]) index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;

temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;
}
A[0][2] = 0;
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++) A[i][2] += A[j][1];
total += A[i][2];
}
avg_wt = (float)total / n;
total = 0;
prin ("P BT WT TAT\n");
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
prin ("P%d %d %d %d\n", A[i][0], A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
prin ("Average Wai ng Time= %f", avg_wt);
prin ("\nAverage Turnaround Time= %f", avg_tat);
}
Ishita Sachan 2200911540057 CSDS-1 G2
Input:-

Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 03
OBJECTIVE:- Implement CPU Scheduling Policies using FCFS
#include <stdio.h>
int main() {
int n, bt[20], wt[20], tat[20], avwt = 0, avtat = 0, i, j;
prin ("Enter total number of processes(maximum 20):");
scanf("%d", &n);
prin ("\nEnter Process Burst Time\n");
for (i = 0; i < n; i++) {
prin ("P[%d]:", i + 1);
scanf("%d", &bt[i]);
}
wt[0] = 0;
{
wt[i] = 0;
for (j = 0; j < i; j++) wt[i] += bt[j];
}
prin ("\nProcess\t\tBurst Time\tWai ng Time\tTurnaround Time");

{
tat[i] = bt[i] + wt[i];
avwt += wt[i];
avtat += tat[i];
prin ("\nP[%d]\t\t%d\t\t%d\t\t%d", i + 1, bt[i], wt[i], tat[i]);
}
avwt /= i;
avtat /= i;
prin ("\n\nAverage Wai ng Time:%d", avwt);
prin ("\nAverage Turnaround Time:%d", avtat);
return 0;
Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 04
OBJECTIVE:- Implement CPU Scheduling Policies using PRIORITY
#include <stdio.h>
int main() {
int bt[20], p[20], wt[20], tat[20], pr[20], i, j, n, total = 0, pos, temp,
avg_wt, avg_tat;
prin ("Enter Total Number of Processes: ");
scanf("%d", &n);
prin ("\nEnter Burst Time and Priority for each process:\n");
for (i = 0; i < n; i++) {
prin ("\nP [%d]\n", i + 1);
prin ("Burst Time: ");
scanf("%d", &bt[i]);
prin ("Priority: ");
scanf("%d", &pr[i]);
p[i] = i + 1;
}
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;
for (i = 1; i < n; i++) {
wt[i] = 0;
for (j = 0; j < i; j++) wt[i] += bt[j];
total += wt[i];
}
for (i = 0; i < n; i++) tat[i] = bt[i] + wt[i];
avg_wt = total / n;
avg_tat = total / n;
prin ("\nProcess\tBurst Time\tPriority\tWai ng Time\tTurnaround Time\n");
for (i = 0; i < n; i++) {
prin ("P%d\t%d\t\t%d\t\t%d\t\t%d\n", p[i], bt[i], pr[i], wt[i], tat[i]);
}
Ishita Sachan 2200911540057 CSDS-1 G2
prin ("\nAverage Wai ng Time = %d\n", avg_wt);
prin ("Average Turnaround Time = %d\n", avg_tat);
return 0;
}
Input:-

Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 05
OBJECTIVE:- Implement CPU Scheduling Policies using ROUND ROBIN
#include <conio.h>
#include <stdio.h>
void main() {
int i, NOP, sum = 0, count = 0, y, quant, wt = 0, tat = 0, at[10], bt[10],
temp[10];
float avg_wt, avg_tat;
prin (" Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP;
for (i = 0; i < NOP; i++) {
prin ("\n Enter the Arrival and Burst me of the Process[%d]\n", i + 1);
prin (" Arrival me is: \t");
scanf("%d", &at[i]);
prin (" \nBurst me is: \t");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
prin ("Enter the Time Quantum for the process: \t");
scanf("%d", &quant);
prin ("\n Process No \t\t Burst Time \t\t TAT \t\t Wai ng Time ");
for (sum = 0, i = 0; y != 0;) {
if (temp[i] <= quant && temp[i] > 0) {
sum = sum + temp[i];
temp[i] = 0;
count = 1;
} else if (temp[i] > 0) {
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if (temp[i] == 0 && count == 1) {
y--;
prin ("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i + 1, bt[i],
sum - at[i], sum - at[i] - bt[i]);
wt = wt + sum - at[i] - bt[i];
tat = tat + sum - at[i];
count = 0;
}
if (i == NOP - 1) {
i = 0;
} else if (at[i + 1] <= sum) {
i++;
} else {
i = 0;
Ishita Sachan 2200911540057 CSDS-1 G2
}
}
avg_wt = wt * 1.0 / NOP;
avg_tat = tat * 1.0 / NOP;
prin ("\n Average Turn Around Time: \t%f", avg_wt);
prin ("\n Average Wai ng Time: \t%f", avg_tat);
getch();
}
Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 06
OBJECTIVE:- WAP of Calcula on of internal fragmenta on .
#include <stdio.h>
#include <stdlib.h>
#define MEMORY_SEGMENT_SIZE 200
#define TOTAL_MEMORY_SIZE 1000
struct Process {
int id;
int size;
};
int total_allocated_memory = 0;
void allocate_memory(struct Process process) {
if (total_allocated_memory + process.size <= TOTAL_MEMORY_SIZE &&
process.size <= MEMORY_SEGMENT_SIZE) {
total_allocated_memory += process.size;
prin (
"Allocated %d MB of memory for process p%d. Total memory allocated: %d "
"MB\n",
process.size, process.id, total_allocated_memory);
} else {
prin ("Not enough memory to allocate %d MB for process p%d\n",
process.size, process.id);
}
}
int main() {
struct Process processes[] =
{{1, 180}, {2, 190}, {3, 200}, {4, 220},{5, 170}, {6, 300}, {7, 190}};
int num_processes = sizeof(processes) / sizeof(processes[0]);
for (int i = 0; i < num_processes; i++) {
allocate_memory(processes[i]);
}

return 0;
}
Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 07
OBJECTIVE:- Implement CPU Scheduling Policies using Mul -level Queue
# include <stdio.h>
struct process {
char name;
int AT, BT, WT, TAT, RT, CT;
} Q1[10], Q2[10], Q3[10];
int n;
void sortByArrival() {
struct process temp;
int i, j;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (Q1[i].AT > Q1[j].AT) {
temp = Q1[i];
Q1[i] = Q1[j];
Q1[j] = temp;
}
}
}
}

int main() {
int i, j, k = 0, r = 0, me = 0, tq1 = 5, tq2 = 8, flag = 0;
char c;
prin ("Enter no of processes:");
scanf("%d", &n);
for (i = 0, c = 'A'; i < n; i++, c++) {
Q1[i].name = c;
prin ("Enter the arrival me and burst me of process %c: ", Q1[i].name);
scanf("%d%d", &Q1[i].AT, &Q1[i].BT);
Q1[i].RT = Q1[i].BT;
}
sortByArrival();
me = Q1[0].AT;
prin ("Process in first queue following RR with qt=5");
prin ("\nProcess\t\tRT\t\tWT\t\tTAT\t\t");
for (i = 0; i < n; i++) {
if (Q1[i].RT <= tq1) {
me += Q1[i].RT;
Q1[i].RT = 0;
Q1[i].WT = me - Q1[i].AT - Q1[i].BT;
Q1[i].TAT = me - Q1[i].AT;
prin ("\n%c\t\t%d\t\t%d\t\t%d", Q1[i].name, Q1[i].BT, Q1[i].WT,
Q1[i].TAT);

} else {
Ishita Sachan 2200911540057 CSDS-1 G2
Q2[k].WT = me;
me += tq1;
Q1[i].RT -= tq1;
Q2[k].BT = Q1[i].RT;
Q2[k].RT = Q2[k].BT;
Q2[k].name = Q1[i].name;
k = k + 1;
flag = 1;
}
}
if (flag == 1) {
prin ("\nProcess in second queue following RR with qt=8");
prin ("\nProcess\t\tRT\t\tWT\t\tTAT\t\t");
}
for (i = 0; i < k; i++) {
if (Q2[i].RT <= tq2) {
me += Q2[i].RT;
Q2[i].RT = 0;
Q2[i].WT = me - tq1 - Q2[i].BT;
Q2[i].TAT = me - Q2[i].AT;
prin ("\n%c\t\t%d\t\t%d\t\t%d", Q2[i].name, Q2[i].BT, Q2[i].WT,
Q2[i].TAT);

} else {
Q3[r].AT = me;
me += tq2;
Q2[i].RT -= tq2;
Q3[r].BT = Q2[i].RT;
Q3[r].RT = Q3[r].BT;
Q3[r].name = Q2[i].name;
r = r + 1;
flag = 2;
}
}

{
if (flag == 2) prin ("\nProcess in third queue following FCFS ");
}
for (i = 0; i < r; i++) {
if (i == 0)
Q3[i].CT = Q3[i].BT + me - tq1 - tq2;
else
Q3[i].CT = Q3[i - 1].CT + Q3[i].BT;
}

for (i = 0; i < r; i++) {


Q3[i].TAT = Q3[i].CT;
Ishita Sachan 2200911540057 CSDS-1 G2
Q3[i].WT = Q3[i].TAT - Q3[i].BT;
prin ("\n%c\t\t%d\t\t%d\t\t%d\t\t", Q3[i].name, Q3[i].BT, Q3[i].WT,
Q3[i].TAT);
}
}
Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 08
OBJECTIVE:- Implementa on of con guous alloca on techniques.
(a). Worst-Fit
#include <conio.h>
#include <stdio.h>
#define max 25
void main() {
int frag[max], b[max], f[max], i, j, nb, nf, temp;
sta c int bf[max], ff[max];
clrscr();
prin ("Memory Management Scheme - First Fit");
prin ("\nEnter the number of blocks:");
scanf("%d", &nb);
prin ("Enter the number of files:");
scanf("%d", &nf);
prin ("\nEnter the size of the blocks:-\n");
for (i = 1; i <= nb; i++) {
prin ("Block %d:", i);
scanf("%d", &b[i]);
}
prin ("Enter the size of the files :-\n");
for (i = 1; i <= nf; i++) {
prin ("File %d:", i);
scanf("%d", &f[i]);
}
for (i = 1; i <= nf; 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]] = 1;
}
prin ("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for (i = 1; i <= nf; i++)
prin ("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]], frag[i]);
getch();
}
Ishita Sachan 2200911540057 CSDS-1 G2
Output:-

(b). Best-Fit
#include <conio.h>
#include <stdio.h>
#define max 25
void main() {
int frag[max], b[max], f[max], i, j, nb, nf, temp, lowest = 10000;
sta c int bf[max], ff[max];
prin ("Enter the number of blocks:");
scanf("%d", &nb);
prin ("Enter the number of files:");
scanf("%d", &nf);
prin ("\nEnter the size of the blocks:-\n");
for (i = 1; i <= nb; i++) {
prin ("Block %d:", i);
scanf("%d", &b[i]);
}
prin ("Enter the size of the files :-\n");
for (i = 1; i <= nf; i++) {
prin ("File %d:", i);
scanf("%d", &f[i]);
}
for (i = 1; i <= nf; 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;
Ishita Sachan 2200911540057 CSDS-1 G2

lowest = temp;
}
}
}
frag[i] = lowest;
bf[ff[i]] = 1;
lowest = 10000;
}
prin ("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for (i = 1; i <= nf && ff[i] != 0; i++)
prin ("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]], frag[i]);
getch();
}

Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 9
OBJECTIVE:- Implementa on of page replacement algorithm using
(a) FIFO
#include <stdio.h>
#define FRAME_SIZE 3
int frames[FRAME_SIZE];
int front = 0;
int rear = 0;
int pageFaults = 0;
void displayFrames() {
for (int i = 0; i < FRAME_SIZE; i++) {
prin ("%d ", frames[i]);
}
prin ("\n");
}
void insertPage(int page) {
int i;
for (i = 0; i < rear; i++) {
if (frames[i] == page) {
prin ("Page %d already in frame.\n", page);
displayFrames();
return;}
}
if (rear < FRAME_SIZE) {
frames[rear++] = page;
} else {
for (i = 0; i < FRAME_SIZE - 1; i++) {
frames[i] = frames[i + 1];
}
frames[i] = page;
}
pageFaults++;
prin ("Page %d inserted:\n", page);
displayFrames();
}
int main() {
int requests[] = {1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4};
int n = sizeof(requests) / sizeof(requests[0]);
for (int i = 0; i < n; i++) {
insertPage(requests[i]);
}
prin ("Total page faults: %d\n", pageFaults);
return 0;
}

Output:-
Ishita Sachan 2200911540057 CSDS-1 G2

(b) LRU
#include <limits.h>
#include <stdio.h>
#define FRAME_SIZE 3
int frames[FRAME_SIZE];
int usage[FRAME_SIZE];
int pageFaults = 0;
int me = 0;
void displayFrames() {
for (int i = 0; i < FRAME_SIZE; i++) {
prin ("%d ", frames[i]); }
prin ("\n");
}
int findLRU() {
int minUsage = INT_MAX, lruIndex = 0;
for (int i = 0; i < FRAME_SIZE; i++) {
if (usage[i] < minUsage) {
minUsage = usage[i];
lruIndex = i;
}
}
return lruIndex;
}
void insertPage(int page) {
int i;
for (i = 0; i < FRAME_SIZE; i++) {
Ishita Sachan 2200911540057 CSDS-1 G2
if (frames[i] == page) {
prin ("Page %d already in frame.\n", page);
usage[i] = ++ me;
displayFrames();
return; }
}
int lruIndex = findLRU();
frames[lruIndex] = page;
usage[lruIndex] = ++ me;
pageFaults++;
prin ("Page %d inserted:\n", page);
displayFrames();
}
int main() {
for (int i = 0; i < FRAME_SIZE; i++) {
frames[i] = -1; //-1 to indicate empty slots
usage[i] = 0;}
int requests[] = {1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4};
int n = sizeof(requests) / sizeof(requests[0]);
for (int i = 0; i < n; i++) {
insertPage(requests[i]);
}
prin ("Total page faults: %d\n", pageFaults);
return 0;
}
Output:-
Ishita Sachan 2200911540057 CSDS-1 G2
PROGRAM NO 10
OBJECTIVE:- Implement file storage alloca on technique: Con guous(using array)
#include <stdio.h>
struct filep {
int id;
int start;
int count;
};
typedef struct filep files;
int main() {
int disk[100];
int i, j, k;
for (i = 0; i < 100; i++) disk[i] = -1;
files f[3];
for (i = 0; i < 3; i++) {
f[i].id = i;
prin ("enter the number of blocks for file : %d \n", i);
scanf("%d", &f[i].count);
}
int flag = 0;
for (i = 0; i < 3; i++) {
flag = 0;
for (j = 0; j < 100; j++) {
if (disk[j] == -1) {
for (k = j; k < j + f[i].count && disk[k] == -1; k++) {
flag++;
prin ("\n flag for file %d : %d\n", i, flag);
}
if (flag == f[i].count) {
for (k = j; k < j + f[i].count; k++) {
f[i].start = j;
disk[k] = f[i].id;
}
j = j + f[i].count;
break;
} else {
j = j + flag;
flag = 0;
}
}
if (j == 99 && flag == 0) prin ("\n disk is full \n");
}
}
prin ("\n here is the disk alloca on details \n");
for (i = 0; i < 100; i++) prin ("%d ", disk[i]);
return 0;
}
Ishita Sachan 2200911540057 CSDS-1 G2
Output:-

You might also like