OS FIle

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

EXPERIMENT 1

Some general requirements and differences between these operating systems:

DOS (Disk Operating System):

Hardware: DOS typically runs on x86-based personal computers with at least a floppy
disk drive and basic input/output devices like a keyboard and display. Older versions
may require less memory, while later versions like MS-DOS 6.22 can run on systems
with at least 512 KB of RAM.

Software: DOS itself serves as a platform for running software applications. Common
software used with DOS includes word processors, spreadsheets, databases, and
games.

UNIX:

Hardware: UNIX is designed for a wide range of computer systems, including


workstations, servers, and embedded systems. It can run on various hardware
architectures, including x86, SPARC, and PowerPC. The specific hardware requirements
depend on the UNIX distribution and version.

Software: UNIX provides a robust set of software tools and utilities for system
administration, development, and networking. It is known for its robust multitasking
and multi-user capabilities, making it suitable for server environments and software
development.

Linux:

Hardware: Linux is highly flexible and can run on a diverse range of hardware
platforms, including desktops, laptops, servers, and even mobile devices. It has
relatively low hardware requirements and can run on systems with limited resources.
However, specific hardware requirements may vary depending on the Linux
distribution and intended use.

Software: Linux distributions typically come with a package management system that
allows users to install, remove, and update software packages easily. Linux offers a
wide range of software options, including office suites, development tools, multimedia
applications, and server software.

Windows XP:

Hardware: Windows XP had minimum system requirements, including a 233 MHz


processor, 64 MB of RAM, and 1.5 GB of available hard drive space. It also required a
CD-ROM drive, a keyboard, and a mouse.
Software: Windows XP came with a range of pre-installed software, including Internet
Explorer, Windows Media Player, and basic productivity tools like WordPad and Paint.
It also supported a wide range of third-party software applications.

Windows 7/8:

Hardware: The hardware requirements for Windows 7 and 8 are generally higher than
those for Windows XP. For example, Windows 7 requires a 1 GHz processor, 1 GB of
RAM (for 32-bit) or 2 GB of RAM (for 64-bit), and 16 GB of hard drive space. Windows
8 has similar requirements but also includes support for touch-enabled devices.

Software: Windows 7 and 8 continued to improve the user interface, multimedia


capabilities, and security features. They introduced new features such as the ribbon
interface in Windows Explorer, improved taskbar functionality, and support for virtual
hard disks.
EXPERIMENT 3 (a)
The execution of Unix system calls involves interacting with the operating system
kernel to perform specific tasks. Here's how the execution of Unix system calls
typically works for process management, file management, and input/output (I/O)
operations:

I. Process Management System Calls:


Process management system calls are used to create, terminate, and control
processes. Here's how they work:

Fork System Call:

Purpose: The fork() system call creates a new process (child process) that is a copy
of the current process (parent process).

Execution: When fork() is called, the kernel creates a new process with the same
memory image as the parent process. The child process has its own process ID (PID)
and executes independently.

Exec System Call :

Purpose: The exec() family of system calls (e.g., execve() ) replaces the current
process image with a new one, effectively loading and executing a specified program.

Execution: The execve() system call takes arguments such as the filename of the
program to execute and any command-line arguments. The kernel then loads the
specified program into memory and begins executing it.

Wait System Call :

Purpose: The wait() or waitpid() system call allows a parent process to wait for
the termination of one of its child processes.

Execution: The parent process calls wait() or waitpid() to block its execution until
a specified child process terminates. The parent can then retrieve the exit status of
the terminated child process.

Exit System Call :

Purpose: The exit() system call terminates the current process and returns an exit
status to the parent process.

Execution: When a process calls exit() , it stops executing, and the kernel performs
cleanup tasks, such as releasing resources and notifying the parent process.

II. File Management System Calls:


File management system calls are used to create, open, read, write, and close files.
Here's how they work:

Open System Call :

Purpose: The open() system call opens a file for reading or writing.
Execution: The open() system call takes a filename and flags (e.g., O_RDONLY,
O_WRONLY, O_CREAT) as arguments. It returns a file descriptor, which is an integer
representing the opened file.

Read and Write System Calls :

Purpose: The read() and write() system calls are used to read data from or write
data to a file, respectively.

Execution: read() takes a file descriptor and a buffer as arguments, reading data
from the file into the buffer. write() takes a file descriptor, a buffer, and the number
of bytes to write as arguments, writing data from the buffer to the file.

Close System Call :

Purpose: The close() system call closes an open file, releasing associated resources.

Execution: close() takes a file descriptor as an argument and releases the file
descriptor, allowing it to be reused.

III. Input/Output (I/O) System Calls:


I/O system calls are used for performing input and output operations on files, devices,
and other resources. Here's how they work:

Standard I/O :

Unix processes typically have three standard file descriptors: standard input (stdin,
file descriptor 0), standard output (stdout, file descriptor 1), and standard error
(stderr, file descriptor 2).

These file descriptors are automatically opened and can be used for input and output
operations.

Input and Output System Calls :

Unix provides a set of standard I/O system calls,


including read() , write() , open() , close() , lseek() , and printf() .

The read() and write() system calls are used for reading from and writing to files or
devices, respectively.

The open() system call opens a file, returning a file descriptor for further I/O
operations.

The close() system call closes an open file descriptor.

The lseek() system call changes the current position within a file.

The printf() function is often used for formatted output to standard output or a
specified file.
EXPERIMENT 2
The execution of DOS internal commands involves several steps and relies on the
COMMAND.COM file, which serves as the command processor for the Disk Operating
System (DOS) and Windows 9x operating systems. Here's how the execution of DOS
internal commands typically works:

1. Boot Process : When a computer with a DOS or Windows 9x operating system is


booted, the COMMAND.COM file is automatically loaded into the computer's
primary memory (RAM). This file contains the code for the internal commands.

2. Availability in Memory : Once COMMAND.COM is loaded into memory, the


internal commands become readily available for execution. They reside in
memory at all times, which allows for quick and immediate access.

3. User Input : To execute an internal command, the user types the command at
the command-line interface (CLI) or the MS-DOS prompt. For example, the user
might type "DIR" to display a list of files in the current directory.

4. Command Interpretation : When the user presses Enter after typing a


command, the COMMAND.COM file interprets the command and performs the
associated action. It recognizes the internal commands because their code is
embedded within COMMAND.COM.

5. Immediate Execution : Since internal commands are already loaded into


memory, they can be executed instantly. There is no need to fetch the
command code from secondary memory (such as a hard disk) before executing
it. This makes internal commands faster and more responsive compared to
external commands.

6. Output : After executing the command, the results are displayed on the screen
or saved to a file, depending on the nature of the command and its parameters.
For example, the "DIR" command would display a list of files and their details
on the screen.

7. Repeat as Needed : The user can continue to enter and execute internal
commands as needed. The internal commands remain in memory throughout
the computer session, allowing for quick and efficient execution without the
overhead of loading them from disk each time.
EXPERIMENT 3 (b)
In Windows operating systems, file management system calls are used to interact with
the file system and perform various operations on files and directories. These system
calls are provided by the Windows API and are typically used by applications to
manage files efficiently. Here's how file management system calls work in Windows:

1. File Creation and Opening :

1.1. CreateFile() : This system call is used to create or open a file. It takes
parameters such as the file name or path, the desired access mode (read,
write, or both), and the sharing mode. It returns a handle to the file if
successful.

2. File Reading and Writing :

2.1. ReadFile() : This system call is used to read data from a file. It takes the
file handle obtained from CreateFile() , a buffer to store the read data,
and the number of bytes to read. It returns the number of bytes actually
read.

2.2. WriteFile() : This system call is used to write data to a file. It takes the
file handle, a buffer containing the data to be written, and the number of
bytes to write. It returns the number of bytes actually written.

3. File Positioning :

3.1. SetFilePointer() : This system call is used to set or retrieve the current
file pointer position. It allows applications to seek to a specific location
within a file.

4. File Truncation :

4.1. SetEndOfFile() : This system call sets the end-of-file (EOF) marker for a
specified file, truncating or extending the file to the specified position.

5. File Information Retrieval :

5.1. GetFileAttributes() : This system call retrieves the attributes of a file,


such as its size, creation and modification dates, and other metadata.

5.2. GetFileInformationByHandle() : This system call retrieves detailed


information about a file, such as its size, timestamps, and security
information, using the file handle.

6. File Time Manipulation :

6.1. SetFileTime() : This system call sets the creation, last access, and last
write times for a file.

7. File Attribute Manipulation :

7.1. SetFileAttributes() : This system call sets the attributes of a file, such
as "hidden," "read-only," or "system."
8. File Deletion :

8.1. DeleteFile() : This system call deletes an existing file.

9. Directory Management :

9.1. CreateDirectory() : This system call creates a new directory.

9.2. RemoveDirectory() : This system call removes an empty directory.

9.3. FindFirstFile() : This system call initiates a search for files or


subdirectories in a specified directory, returning information about the first
file or subdirectory found.

9.4. FindNextFile() : This system call continues a file search started


by FindFirstFile() , returning information about the next file or
subdirectory.

10. File and Directory Enumeration :

10.1. EnumFiles() : This system call enumerates files and directories within a
specified directory, allowing applications to iterate through the contents of
a directory.

11. File and Directory Security :

11.1. GetFileSecurity() : This system call retrieves the security descriptor of a


file or directory, which contains information about access control and
permissions.

11.2. SetFileSecurity() : This system call sets the security descriptor of a file
or directory, allowing applications to modify access control settings.
EXPERIMENT 4 (a)
# Python3 program to Calculate Waiting

# Time for given Processes

# Function to Calculate waiting time

# and average waiting time

def CalculateWaitingTime(at, bt, N):

# Declare the array for waiting

# time

wt = [0]*N;

# Waiting time for first process

# is 0

wt[0] = 0;

# Print waiting time process 1

print("P.No.\tArrival Time\t" , "Burst Time\tWaiting Time");

print("1" , "\t\t" , at[0] , "\t\t" , bt[0] , "\t\t" , wt[0]);

# Calculating waiting time for

# each process from the given

# formula

for i in range(1,5):

wt[i] = (at[i - 1] + bt[i - 1] + wt[i - 1]) - at[i];

# Print the waiting time for

# each process

print(i + 1 , "\t\t" , at[i] , "\t\t" , bt[i] , "\t\t" , wt[i]);

# Declare variable to calculate

# average

average = 0.0;

sum = 0;

# Loop to calculate sum of all

# waiting time

for i in range(5):

sum = sum + wt[i];


# Find average waiting time

# by dividing it by no. of process

average = sum / 5;

# Print Average Waiting Time

print("Average waiting time = " , average);

# Driver code

if __name__ == '__main__':

# Number of process

N = 5;

# Array for Arrival time

at = [ 0, 1, 2, 3, 4 ];

# Array for Burst Time

bt = [ 4, 3, 1, 2, 5 ];

# Function call to find

# waiting time

CalculateWaitingTime(at, bt, N);


EXPERIMENT 4 (a)
#include<stdio.h>
#define MAX 20

int main()

{
int n,bt[MAX],wt[MAX],tat[MAX],avwt=0,avtat=0,i,j;
printf("Enter total number of processes(maximum 20):");
scanf("%d",&n);

printf("nEnter Process Burst Timen");


for(i=0;i<n;i++)
{
printf("P[%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("nProcessttBurst TimetWaiting TimetTurnaround Time");

for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);
}

avwt/=i;
avtat/=i;
printf("nnAverage Waiting Time:%d",avwt);
printf("nAverage Turnaround Time:%d",avtat);

return 0;
}
EXPERIMENT 5 (a)
#include <stdio.h>
int main()
{
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time.
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
// User Input Burst Time and alloting Process Id.
for (i = 0; i < n; i++) {
printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
}
// Sorting process according to their Burst Time.
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;
// Calculation of Waiting Times
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;
printf("P BT WT TAT\n");
// Calculation of Turn Around Time and printing the
// data.
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
A[i][1], A[i][2], A[i][3]);
}
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}
EXPERIMENT 6 (a)
// C program to implement Shortest Remaining Time First
// Shortest Remaining Time First (SRTF)

#include <stdio.h>
#include <limits.h>

struct Process {
int pid; // Process ID
int bt; // Burst Time
int art; // Arrival Time
};

// Function to find the waiting time for all


// processes
void findWaitingTime(struct Process proc[], int n, int wt[])
{
int rt[n];

// Copy the burst time into rt[]


for (int i = 0; i < n; i++)
rt[i] = proc[i].bt;

int complete = 0, t = 0, minm = INT_MAX;


int shortest = 0, finish_time;
int check = 0; // changed boolean to integer

// Process until all processes gets


// completed
while (complete != n) {

// Find process with minimum


// remaining time among the
// processes that arrives till the
// current time
for (int j = 0; j < n; j++) {
if ((proc[j].art <= t) &&
(rt[j] < minm) && rt[j] > 0) {
minm = rt[j];
shortest = j;
check = 1; // changed boolean to integer
}
}

if (check == 0) {
t++;
continue;
}

// Reduce remaining time by one


rt[shortest]--;

// Update minimum
minm = rt[shortest];
if (minm == 0)
minm = INT_MAX;

// If a process gets completely


// executed
if (rt[shortest] == 0) {

// Increment complete
complete++;
check = 0; // changed boolean to integer
// Find finish time of current
// process
finish_time = t + 1;

// Calculate waiting time


wt[shortest] = finish_time -
proc[shortest].bt -
proc[shortest].art;

if (wt[shortest] < 0)
wt[shortest] = 0;
}
// Increment time
t++;
}
}

// Function to calculate turn around time


void findTurnAroundTime(struct Process proc[], int n, int
wt[], int tat[]) {
// calculating turnaround time by adding
// bt[i] + wt[i]
for (int i = 0; i < n; i++)
tat[i] = proc[i].bt + wt[i];
}

// Function to calculate average time


void findavgTime(struct Process proc[], int n) {
int wt[n], tat[n], total_wt = 0,
total_tat = 0;

// Function to find waiting time of all


// processes
findWaitingTime(proc, n, wt);

// Function to find turn around time for


// all processes
findTurnAroundTime(proc, n, wt, tat);

// Display processes along with all


// details
printf(" P\t\t"
"BT\t\t"
"WT\t\t"
"TAT\t\t\n");

// Calculate total waiting time and


// total turnaround time
for (int i = 0; i < n; i++) {
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d\t\t"
"%d\t\t %d"
"\t\t %d\n", proc[i].pid,
proc[i].bt, wt[i], tat[i]);
}

printf("\nAverage waiting time = "


"%f", (float)total_wt / (float)n);
printf("\nAverage turn around time = "
"%f", (float)total_tat / (float)n);
}

// Driver code
int main() {
struct Process proc[] = { { 1, 6, 2 }, { 2, 2, 5 },
{ 3, 8, 1 }, { 4, 3, 0}, {5, 4, 4} };
int n = sizeof(proc) / sizeof(proc[0]);

findavgTime(proc, n);
return 0;
}
EXPERIMENT 7 (a)
#include<stdio.h>

int main()
{

int cnt,j,n,t,remain,flag=0,tq;
int wt=0,tat=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(cnt=0;cnt<n;cnt++)
{
printf("Enter Arrival Time and Burst Time for Process
Process Number %d :",cnt+1);
scanf("%d",&at[cnt]);
scanf("%d",&bt[cnt]);
rt[cnt]=bt[cnt];
}
printf("Enter Time Quantum:\t");
scanf("%d",&tq);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(t=0,cnt=0;remain!=0;)
{
if(rt[cnt]<=tq && rt[cnt]>0)
{
t+=rt[cnt];
rt[cnt]=0;
flag=1;
}
else if(rt[cnt]>0)
{
rt[cnt]-=tq;
t+=tq;
}
if(rt[cnt]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",cnt+1,t-at[cnt],t-
at[cnt]-bt[cnt]);
wt+=t-at[cnt]-bt[cnt];
tat+=t-at[cnt];
flag=0;
}
if(cnt==n-1)
cnt=0;
else if(at[cnt+1]<=t)
cnt++;
else
cnt=0;
}
printf("\nAverage Waiting Time= %f\n",wt*1.0/n);
printf("Avg Turnaround Time = %f",tat*1.0/n);

return 0;
}
EXPERIMENT 8
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First 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]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("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;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\
tFragement"); for(i=1;i<=nf;i++)
printf("\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();
}

EXPERIMENT 9
#include<stdio.h>
#include<conio.h>
#define max 25

void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme – Best 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]);

printf("Enter the size of the files :-\n");


for(i=1;i<=nf;i++)
{
printf("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;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\
tFragment");
for(i=1;i<=nf && ff[i]!=0;i++)
printf("\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();
}

EXPERIMENT 10
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();

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]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{

for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
ff[i]=j;
highest=temp;

}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
}

ff[i]=j;
highest=temp;
}

printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\
tFragement");
for(i=1;i<=nf;i++)
printf("\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();
}

You might also like