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

Practical File

Of

“OPERATING SYSTEMS
LAB”
PC-CS-212AL
Submitted to: Submitted by:

Mrs. Mamta Gupta Leena

Univ. Roll no. : 2021218212


B. Tech CSE (4th sem)
INDEX
Sr. no. Date Program signature

1. 10-03-23 To study of hardware and


software requirement of
various operating system.

2. 10-03-23 To study of system calls.

3. 17-03-23 Implementation of first


come first serve (FCFS)

Implementation of shortest
4. 17-03-23 job first serve (SJFS)

Implementation of priority
5. 31-03-23 scheduling

Implementation of Round
6. 31-03-23 Robin scheduling

7. 21-04-23 Program to Implement


memory allocation.

8. 28-04-23 Program to implement


resource allocation graph

9. 05-05-23 Implement Wait for graph.


Implementation of internal
10. 05-05-23
and external fragmentation.
Program No.: 1

Aim : To study of hardware & software requirements of 4 various operating system.


Windows 98 system requirements
 A personal computer with a 486DX 66 megahertz (Mitz) or faster processor (Pentium central
processing unit recommended).
 16 megabytes (MB) of memory (24 MB recommended).
 A typical upgrade from Windows 95 requires approximately 195 MB of free hard disk space,
but the hard disk space may range from between 120 MB and 295 MB, depending on your
computer configuration and the options that you choose to install.
 A full install of Windows 98 on a FAT16 drive requires 225 MB of free hard disk space, but
may range from between 165 MB and 355 MB, depending on your computer configuration
and that options that you choose to install.
 A full install of Windows 98 on a FAT32 drive requires 175 MB of free hard disk space, but
may range from between 140 MB and 255 MB, depending on your computer configuration
and the options that you choose to install.
 One 3.5-inch high-density floppy disk drive.
 VGA or higher resolution (16-bit or 24-bit colour SVGA recommended).

Windows 2000 system requirements


 133 MHz or more Pentium microprocessor (or equivalent), Windows 2000 Professional
supports up to two processors on a single computer.
 64 megabytes (MB) of RAM recommended minimum. 32 MB of RAM is the minimum
supported. 4 gigabytes (GB) of RAM is the maximum.
 A 2GB hard disk that has 650 MB of free space. If you are installing over a network, more
free hard disk space is required.
 VGA or higher-resolution monitor.
 Keyboard.
 Mouse or compatible pointing device (optional).
 For CD-ROM installation:
 CD drive or DVD drive
 High-density 3.5-inch disk drive, unless your CD drive supports starting the Setup
program from a CD
 For network installation:
 Windows 2000-compatible network adapter and related cable (See the Hardware
Compatibility List (Hel.txt) in the Support folder on the Windows 2000 Professional
CD)
 Access to the network share that contains the Setup files
Windows xp system requirements
 Pentium 233-megahertz (MHz) processor or faster (300 MHz is recommended)
 At least 64 megabytes (MII) of RAM (128 MI) is recommended)
 At least 1.5 gigabytes (GI) of available space on the hard disk
 CD-ROM or DVD-ROM drive
 Keyboard and a Microsoft Mouse or some other compatible pointing device
 Video adapter and monitor with Super VGA (800 x 600)or higher resolution
 Sound card
 Speakers or headphones
Windows Vista system requirements

Windows Vista Home Basic


 800-megahertz (MHz) 32-bit (x86) processor or 800-MHz 64-bit (x64) processor
 512 megabytes (MB) of system memory
 DirectX 9-class graphics card
 32 MB of graphics memory
 20-gigabyte (GB) hard disk that has 15 GB of free hard disk space
 Internal or external DVD drive
 Internet access capability
 Audio output capability

Windows Vista Home Premium. Windows Vista Business. Windows Vista Enterprise..and
Windows Vista Ultimate
 1-gigahertz (GHz) 32-bit (x86) processor or 1-GHz 64-bit (x64) processor
 1 GB of system memory
 Windows Aero-capable graphics card
Note This includes a DirectX 9-class graphics card.
 128 MB of graphics memory (minimum)
 40-GB hard disk that has 15 GB of free hard disk space (the 15GB of free space provides
room for temporary file storage during the install or upgrade.)
 Internal or external DVD drive
 Internet access capability
 Audio output capability

Windows 7 system requirements


 1 gigahertz (GHz) or faster 32-bit (x86) or 64-bit (x64) processor
 1 gigabyte (GB) RAM (32-bit) or 2 GB RAM (64-bit)
 16 GB available hard disk space (32-bit) or 20 GB (64-bit)
 DirectX 9 graphics device with WDDM 1.0 or higher driver.
Windows 8 system requirements
 Processor: I gigahertz (GHz) or faster with support for PAE, NX, and SSE2
 RAM: 1 gigabyte (GB) (32-bit) or 2 GB (64-bit)
 Hard disk space: 16 GB (32-bit) or 20 GB (64-bit)
 Graphics card: Microsoft DirectX 9 graphics device with WDDM driver.
Program No.:.2

Aim: To study of system calls.


In computing, a system call is how a program requests a service from an operating system's kernel.
This may include hardware related services (e.g., accessing the hard disk, creating and executing new
processes, and communicating with integral Kernel services (like scheduling). System calls provide
an essential interface between a process and the operating system.
Privileges
The design of the microprocessor architecture on practically all modern systems (except some
embedded systems) involves a security model (such as the rings model) which specifies multiple
privilege levels under which software may be executed: for instance, a program is usually limited to
its own address space so that it cannot access or modify other running programs or the operating
system itself, and a program is usually prevented from directly manipulating hardware devices (e.g.
the frame buffer or network devices).
However, many normal applications obviously need access to these components, so system calls are
made available by the operating system to provide well-defined, safe implementations for such
operations. The operating system executes at the highest level of privilege, and allows applications to
request services via system calls, which are often executed via interrupts; an interrupt automatically
puts the CPU into some required privilege level, and then passes control to the kernel, which
determines whether the calling program should be granted the requested service. If the service is
granted, the kernel executes a specific set of instructions over which the calling program has no direct
control, returns the privilege level to that of the calling program, and then returns control to the calling
program.
The library as an Intermediary
Generally, systems provide a library or API that sits between normal programs and the operating
system. On Unix-like systems, that API is usually part of an implementation of the C library (libe),
such as glibe. that provides wrapper functions for the system calls, often named the same as the
system calls that they call On Windows NT, that API is part of the Native API, in thentdll.dil library;
this is an undocumented API used by implementations of the regular Windows API and directly used
by some system programs on Windows. The library's wrapper functions expose an ordinary function
calling convention (a subroutine call on the assembly level) for using the system call, as well as
making the system call more modular. Here, the primary function of the wrapper is to place all the
arguments to be passed to the system call in the appropriate processor registers (and maybe on the call
stack as well), and also setting a unique system call number for the kernel to call. In this way the
library, which exists between the OS and the application, increases portability?
The call to the library function itself does not cause a switch to kernel mode (if the execution was not
already in kernel mode) and is usually a normal subroutine call (using, for example, a "CALL"
assembly instruction in some Instruction (ISAs)). The actual system call does transfer control to the
kernel (and is more implementation-dependent and platform-dependent than the library call
abstracting it). For example, in like systems, "fork" and "execve" are C library functions that in turn
execute instructions that invoke the "fork" and "execve" system calls. Making the system call directly
in the application code is more complicated and may require embedded assembly code to be used (in
C and C++) as well as knowledge of the low-level binary interface for the system call operation,
which may be subject to change over time and thus not be part of the application binary interface; the
library functions are meant to abstract this away.
On exokernel based systems, the library is especially important as an intermediary, On exokernels,
libraries shield user applications from the very low level kernel API, and provide abstractions and
resource management.
Examples.and.tools
On Unix, Unix-like and other POSIX-compatible operating systems, popular system calls
are open, read, write, close, wait, exeuve, fork, exit, and kill. Many of today's operating systems have
hundreds of system calls. For example, Linus has over 300 different calls, PreeBSD has over 500,
while Plan 9 has 51.
Tools such as strace and truss allow a process to execute from start and report all system calls the
process invokes, or can attach to an already running process and intercept any system call made by
said process if the operation does not violate the permissions of the user. This special ability of the
program is usually also implemented with a system call, eg, strace is implemented with ptrace or
system calls on files in procfs.
Typical implementations
Implementing system calls requires a control transfer which involves some sort of architecture-
specific feature. A typical way to implement this is to use a software interrupt or trap. Interrupts
transfer control to the operating system kernel so software simply needs to set up some register with
the system call number needed, and execute the software interrupt.
For many RISC processors this is the only technique provided, but CISC architectures such as x86
support additional techniques. One example is SYSCALL/SYSENTER, SYSRET/SYSEXIT (the two
mechanisms were independently created by AMD and Intel, respectively, but in essence do the same
thing). These are "fast" control transfer instructions that are designed to quickly transfer control to the
OS for a system call without the overhead of an interrupt. Linux 2.5 began using this on the x86,
where available; formerly it used the INT instruction, where the system call number was placed in the
EAX register before interrupt 0x80 was executed.
An older x86 mechanism is called a call gate and is a way for a program to literally call a kernel
function directly using a safe control transfer mechanism the OS sets up in advance. This approach
has been unpopular. presumably due to the requirement of a far call which uses x86 memory
segmentation and the resulting lack of portability it causes and existence of the faster instructions
mentioned above.
For IA-64 architecture, EPC (Enter Privileged Mode) instruction is used. The first eight system call
arguments are passed in registers, and the rest are passed on the stack.
In the IBM System/360 mainframe family, a instruction implements a system call.
System calls can be roughly grouped into five major categories:
1. Process Control
 Load
 Execute
 create process (for example, fork on Unix-like systems or NTCreateProcess in the
Windows NT Native API)
 terminate process
 get/set process attributes
 wait for time, wait event, signal event
 allocate, free memory
2. File management
 create file, delete file
 open, close
 read, write, reposition
 get/set file attributes
3. Device Management
 request device, release device
 read, write, reposition
 get/set device attributes
 logically attach or detach devices
4. Information Maintenance
 get/set time or date
 get/set system data
 get/set process, file, or device attributes
5. Communication
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices
Program No. : 3

Aim : Write a program to implement First-Come, First-Served (FCFS) scheduling.

Sourcecode:
#include<conio.h>
#include<stdio.h>
main()
{
int i,n,a[20];
float t=0.0,w=0.0;
clrscr();
printf("FCFS");
printf("\nEnter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
t=t+a[i];
if(i!=n)
w=w+t;
}
t=t/n;
w=w/n;
printf("\nAverage turn around time %f ",t);
printf("\nAverage waiting time : %f",w);
getch();
}

Output:
Program No. : 4
Aim : Write a program to implement Shortest-Job-First-Serverd (SJFS) Scheduling.

Sourcecode:
#include<conio.h>
#include<stdio.h>
main()
{
int i,n,j,k,temp,a[20];
float t=0.0,w=0.0;
clrscr();
printf("SJFS");
printf("\nEnter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(j=1;j<=n;j++)
{
for(k=j+1;k<=n;k++)
{
if(a[j]>a[k])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
}
t=t+a[j];
if(j!=n)
w=w+t;
}
t=t/n;
w=w/n;
printf("\nAverage turn around time : %f ",t);
printf("\nAverage waiting time : %f",w);
getch();
}

Output:
Program No. : 5
Aim : Write a program to implement Priority scheduling.

Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int p[20],b[20],temp1,temp2,i,j,n;
float d=0.0,w=0.0,t=0.0;
clrscr();
printf("\nEnter the total no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\nEnter the priority of the processes : ");
for(i=1;i<=n;i++)
scanf("%d",&p[i]);
printf("\nAccording to priority arrangement of processes are ");
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i]>p[j])
{
temp1=p[i];
p[i]=p[j];
p[j]=temp1;
temp2=b[i];
b[i]=b[j];
b[j]=temp2;
}
}
printf("\n %d",b[i]);
}
for(i=1;i<=n;i++)
d=b[i]+d;
d=d/n;
printf("\nTurn around time is %f ",d);
for(i=1;i<n;i++)
{
w=w+b[i];
t=t+w;
}
t=t/n;
printf("\nAverage waiting time is %f ",t);
getch();
Output:
Program No. : 6
Aim : Write a program to implement Round-Robin Scheduling.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int bt[50],st[50],wt[50],tat[50],i,j,n,tq,temp,count=0,swt=0,stat=0,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter the no. of processes : ");
scanf("%d",&n);
printf("\nEnter the burst time of processes : ");
for(i=1;i<=n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("\nEnter the time quantum process : ");
scanf("%d",&tq);
while(1)
{
for(i=1,count=0;i<=n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>=tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=1;i<=n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+bt[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("\nTurn around time is = %f ",atat);
printf("\nWaiting time is = %f ",awt);
getch();
}
Output:

Program No. : 7
Aim : Write a program to implement Memory allocation.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int i,n,ps,a[20],b[20],small,large,index;
clrscr();
printf("\nEnter the no. of memory blocks : ");
scanf("%d",&n);
printf("\nEnter the size of memory blocks : ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter the size of new process : ");
scanf("%d",&ps);
for(i=0;i<n;i++)
{
if(a[i]>=ps)
{
index=i;
break;
}
}
printf("\nFirst fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
for(i=0;i<n;i++)
{
b[i]=a[i]-ps;
}
small=b[0];
for(i=0;i<n;i++)
{
if(b[i]<small&&b[i]>=0)
{
small=b[i];
index=i;
}
}
printf("\n\nBest fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
large=b[0];
for(i=0;i<n;i++)
{
if(b[i]>large&&b[i]>=0)
{
large=b[i];
index=i;
}
}
printf("\n\nWorst fit : ");
printf("%d",a[index]);
printf("\nBlock no. : ");
printf("%d",index);
getch();
}

Output:

Program No. : 8
Aim : Write a program to implement Resource Allocation Graph.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int pr,re,i,j,pn,rn,ch,p[10][10],r[10][10],flag;
clrscr();
printf("Enter the no. of process : ");
scanf("%d",&pr);
printf("\nEnter the no. of resources : ");
scanf("%d",&re);
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
p[i][j]=0;
}
for(i=1;i<=re;i++)
{
for(j=1;j<=pr;j++)
r[i][j]=0;
}
do
{
printf("\nEnter the process number : ");
scanf("%d",&pn);
if(pn>pr)
printf("\nProcess not present");
printf("\nEnter the resource no. : ");
scanf("%d",&rn);
if(rn>re)
printf("\nResource not present.");
for(i=1;i<=pr;i++)
{
if(r[rn][i]==0)
{
flag=1;
r[rn][i]=2;
}
}
if(flag==1)
p[pn][rn]=1;
else
r[rn][pn]=1;
printf("\n\nAny more process then press 1 or press 2 : ");
scanf("%d",&ch);
flag=0;
}while(ch==1);
printf("\n\nResource allocation graph is : ");
for(i=1;i<=pr;i++)
for(j=1;j<=re;j++)
if(p[i][j]==1)
printf("\nR%d------>P%d",j,i);
for(i=1;i<=re;i++)
for(j=1;j<=pr;j++)
if(r[i][j]==1)
printf("\nP%d......>R%d",j,i);
getch();
}

Output:

Program No. : 9
Aim : Write a program to implement wait for graph.
Sourcecode:
#include<stdio.h>
#include<conio.h>
main()
{
int pr,re,i,j,k,pn,rn,ch,p[10][10],w[10][10],r[10][10],flag;
clrscr();
printf("Enter the no. of process : ");
scanf("%d",&pr);
printf("\nEnter the no. of resources : ");
scanf("%d",&re);
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
p[i][j]=0;
}
for(i=1;i<=re;i++)
{
for(j=1;j<=pr;j++)
r[i][j]=0;
}
do
{
printf("\nEnter the process number : ");
scanf("%d",&pn);
if(pn>pr)
printf("\nProcess not present");
printf("\nEnter the resource no. : ");
scanf("%d",&rn);
if(rn>re)
printf("\nResource not present.");
for(i=1;i<=pr;i++)
{
if(r[rn][i]==0)
{
flag=1;
r[rn][i]=2;
}
}
if(flag==1)
p[pn][rn]=1;
else
r[rn][pn]=1;
printf("\n\nAny more process then press 1 or press 2 : ");
scanf("%d",&ch);
flag=0;
}while(ch==1);
printf("\n\nResource allocation graph is : ");
for(i=1;i<=pr;i++)
for(j=1;j<=re;j++)
if(p[i][j]==1)
printf("\nR%d------>P%d",j,i);
for(i=1;i<=re;i++)
for(j=1;j<=pr;j++)
if(r[i][j]==1)
printf("\nP%d......>R%d",j,i);
for(i=1;i<=pr;i++)
{
for(j=1;j<=pr;j++)
{
w[i][j]=0;
}
}
for(i=1;i<=pr;i++)
{
for(j=1;j<=re;j++)
{
for(k=1;k<=pr;k++)
{
if((p[i][j]==1)&&(r[j][k]==1)&&(i!=k))
{
w[k][i]=1;
}
}
}
}
printf("\n\nWait for graph is ");
for(i=1;i<=pr;i++)
{
for(j=1;j<=pr;j++)
{
if(w[i][j]==1)
{
printf("\nP%d---->P%d",i,j);
}
}
}
getch();
}

Output:
Program No. : 10
Aim : Write a program to implement internal and external fragmentation.
Sourcecode:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[20],temp[20],i,n,p,t,loc,sz,flag[20],x=0;
clrscr();
printf("Enter the memory space : ");
scanf("%d",&p);
printf("\nEnter the total no. blocks : ");
scanf("%d",&n);
printf("\nEnter the size of blocks : ");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
x=x+a[i];
}
if(x>p)
{
printf("\nWrong partition!!!!");
getch();
exit(0);
}
for(i=1;i<=n;i++)
{
flag[i]=0;
}
printf("\nEnter the size of process : ");
scanf("%d",&sz);
printf("\nBest fit");
for(i=1;i<=n;i++)
{
temp[i]=a[i]-sz;
}
t=p;
for(i=1;i<=n;i++)
{
if((t>temp[i])&&(temp[i]>=0)&&(flag[i]==0))
{
t=temp[i];
loc=i;
}
}
if(t!=p)
{
printf("\nInternal fragmentation at the location : %d",loc);
a[loc]=t;
flag[loc]=1;
}
else
{
printf("\nExternal fragmentation ");
for(i=1;i<=n;i++)
{
if(flag[i]==0)
{
printf("\n\nTotal free space %d at the location %d",a[i],i);
}
}
for(i=1;i<=n;i++)
{
if(flag[i]==1)
{
printf("\n\nTotal free space %d at the location %d",a[i],i);
}
}
}
getch();
}
Output:

You might also like