OS FIle
OS FIle
OS FIle
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:
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:
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 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:
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.
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.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.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.
6.1. SetFileTime() : This system call sets the creation, last access, and last
write times for a file.
7.1. SetFileAttributes() : This system call sets the attributes of a file, such
as "hidden," "read-only," or "system."
8. File Deletion :
9. Directory Management :
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.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
wt = [0]*N;
# is 0
wt[0] = 0;
# formula
for i in range(1,5):
# each process
# average
average = 0.0;
sum = 0;
# waiting time
for i in range(5):
average = sum / 5;
# Driver code
if __name__ == '__main__':
# Number of process
N = 5;
at = [ 0, 1, 2, 3, 4 ];
bt = [ 4, 3, 1, 2, 5 ];
# waiting time
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);
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
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
};
if (check == 0) {
t++;
continue;
}
// Update minimum
minm = rt[shortest];
if (minm == 0)
minm = INT_MAX;
// Increment complete
complete++;
check = 0; // changed boolean to integer
// Find finish time of current
// process
finish_time = t + 1;
if (wt[shortest] < 0)
wt[shortest] = 0;
}
// Increment time
t++;
}
}
// 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]);
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();
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();
}