Uma Doc Os

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Operating System Lab (BCS - 451)

EXPERIMENT -1

Objective: Perform the Comparative Analysis of different Operating Systems.


Theory:

Windows Linux Mac UNIX Android iOS


Manufactur Microsoft Inc. Linux is Apple Inc. Three biggest Open source Apple Inc.
er developed as for their distributions OS designed closed, with
open source OS Macintosh are Solaris &developed components
under line of running by Android that are
the GNU project computer (Oracle), Inc. Google is source openly
by systems. AIXon (IBM) now the
the Originator, & HP- current owner
Linus UX Hewlett
Torvalds and Packard.
many And Apple
others. Makes
OSX, an Unix
based
OS

Developmen Developed and Linux is Open Mac OS was Unix system OHA (Open Apple Inc.
t distributed by Sourced and designed has Handset developed
and Microsoft. distributed by only to be various Alliance) and
Distribution various deployed by flavors, most distributed
vendors. Apple of iOS
Computers. which are
developed by
AT&T with
other
commercial
vendors
and non-profit
orgs

Computer x86, x86-64 x86, x86-64, 68k, Available on Android-x86 ARM


Architectur PowerPC, PowerPC PA-RISC powered by
e SPARC, and Itanium AMD and
Supported Alpha, Others machines. Intelx86
Solaris also processors
available
for x86/x64
based
systems. OSX
is
PowerPC(10.
0-
10.5)/x86(10.
4)/x64
(10.5-10.8)

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

Target Workstation, Desktop/Server Workstation, 8086 UNIX Consumer, Smartphone,


System Personal Depends on Personal system, Enterprise, music system
Type Computer, Distribution Computer, PDP-11/70 education player, Tablet
Media Centre, embedded system system/compu
Tablet PC, ter
Embedded.

File System NTFS, FAT & ext2, ext3, HFS+, HFS, jfs, gpfs, hfs, Ext4 HFS+, FTP
Supported exFAT with ex4,ReiserFS,FAT MFS (Mac hfs+, ufs,
ISO , OS 8.0 and xfs, zfs format
9660; UDF, ISO 9660,UDF, before) AFP,
rd NFS, with ISO
3
and others 9660, FAT,
Party driver UDF
that
supports file
system
ext2, and ext3,
ReiserFS, and
HFS

User Very User Depends on Very User Unix is Very User Very User
Friendly Friendly Distribution. Friendly user-friendly. Friendly Friendly
for Lay More It's just
Users friendlier to users choosy about

Integrated Windows Chroot Application IPFilter iptables Firewall-IP


Firewall Firewall capability- Firewall for iOS
based security, [s
5]
seccomp,
SELinux

Security Huge Negligible Negligible Mild Negligible Negligible


Threats

Shell CMD Bash shell BASH Originally the Blink Shell


Terminal powerful Bourne
shell with many Shell. Now
features it's
compatible
with many
others
including
BASH,
Korn & C.

Kernel Type Hybrid Monolithic with Monolithic Monolithic Linux kernel XNU kernel;
modules with with of Darwin
modules modules

Reliability Great Great Greatest Greater Could be More than


unstable

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

Compatibili Can coexist on Linux has few Only few Unix does not Better than Compatibility
ty local programs and programs have as iOS is fair
networks with games will run on many
Windows, BSD, like Windows. Mac programs and
Macs, and other But is games as
Unix-like more compatible Windows
systems. and
More scalable than
compatible. Unix

Examples Early versions Fedora, Debian, ● ac OS X 10.0. 4 IBM AIX, Android 11 iOS 10
Red Hat, Ubuntu, Darwin, Solaris, Android 10
(Windows NT Cheetah. iOS 11
3.1/3.5/3.51/4.0/2 Android, etc HP-UX, macOS
● Mac OS X 10.1. 5
X, etc. iOS 12
000) Puma.
● Windows XP.
iOS 13
● Mac OS X 10.2. 8
Jaguar.
iOS 14
Windows Vista.
iOS 15
● Windows 7. ● Mac OS X 10.3. 9
Panther. iOS 16
Windows 8 and iOS 17
8.1. Mac OS X 10.4. 11
Tiger.
● Windows 10.
● Mac OS X 10.5. 8
● Windows 11.
Leopard.
● Mac OS X 10.6. 8
Snow Leopard.
OS X 10.7. 5 Lion.

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -2

Objective: List 10 UNIX commands.


Theory:

1. access():
The access() function in Unix is a system call that is used to check whether the calling
process can access a particular file or directory with the specified permissions. It takes
two arguments: a pointer to a character string that contains the name of the file or
directory to be checked, and an integer representing the mode of access that is being
checked.

Eg . access(filename,R_OK);

2. chdir():
In Unix-like operating systems, the chdir() system call is used to change the current
working directory of a process. The chdir() function is defined in the <unistd.h> header
file and takes a single argument, which is a string specifying the path to the new working
directory. the new path can be specified as an absolute path or a relative path.

Eg. chdir(“/user/bin”)

3. chmod():
In Unix-like operating systems, the chmod() , is a command used to change the
permission (ie. read, write, execute) on a file or directory . The name chmod stands for “
changes in mode”.
The chmod() uses three-digit code to specify the new permission for a file or directory.
Each digit represents the permission for a different user or group.

Eg chmod(755,myfile)

4. chown():
In a UNIX-like operating system, chown() is a command used to change the owner and or
group of a file or directory. The name Chown stands for “change owner”.
The chown() command takes two arguments: the new owner and or group and the name
of the file or directory to be modified. The new owner and or group can be specified
using a username or numeric ID (UID), a group name, or a numeric group ID (GID).

Eg. chown(alice:developers myfile.txt)

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

5. kill():
In a UNIX-like operating system , kill() is a command used to send a signal to a process,
requesting that it terminate or perform some other actions.

Eg. kill(91734)

6. link():
In Unix-like operating systems, the link() function is used to create a hard link between
two files. A hard link is a way to associate a new name link with an existing file on the
filesystem , without creating a new copy of the file’s contents.

Eg. link(existing file, new file)

7. stime():
In Unix-like operating systems , the stime() function is used to set the system time . the
functions takes a pointer to a time_t value that specifies the new system time.

Eg. stime(cost time t * t );

8. open():
In Unix-like operating systems , the open() function is used to open a file and obtain a file
descriptor , which is a small integer that represents the file in the kernel’s internal tables .

Eg. open(path, flags, mode);

9. times():
In Unix-like operating systems , the times() function is used to get process and system
times . The functions return the elapsed real time since some points in the past , as well as
the amount of CPU time used by the calling process and its children.

Eg. times(struct tms *buf)

10. link():

In Unix-like operating systems, the link() function is used to create a hard link between
two files. A hard link is a way to associate a new name link with an existing file on the
filesystem , without creating a new copy of the file’s contents.

Eg. link(existing file, new file)

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -3(a)

Objective: Write a program to implement First Come First Serve (FCFS)

Code:

#include<stdio.h>
void findWaitingTime(int processes[], int n, int bt[], int wt[])
{
wt[0] = 0;
for (int i = 1; i < n ; i++ )
wt[i] = bt[i-1] + wt[i-1] ;
}
void findTurnAroundTime( int processes[],int n, int bt[], int wt[])

int bt[], int wt[], int tat[])


{
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
void findavgTime( int processes[], int n, int bt[])
{
int wt[n], tat[n], total_wt = 0, total_tat = 0;
findWaitingTime(processes, n, bt, wt);
findTurnAroundTime(processes, n, bt, wt, tat);
printf("Processes BurstTime WaitingTime TurnAroundTime\n");
for (int i=0; i<n; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
printf(" %d ",(i+1));
printf(" %d ", bt[i] );
printf(" %d",wt[i] );
printf(" %d\n",tat[i] );
}
float s=(float)total_wt / (float)n;
float t=(float)total_tat / (float)n;
printf("Average waiting time = %f",s);
printf("\n");
printf("Average turn around time = %f ",t);
}
int main()
{int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
int burst_time[] = {10, 5, 8};
findavgTime(processes, n, burst_time);
return 0; }

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

OUTPUT:
Processes BurstTime WaitingTime TurnAroundTime
1 10 0 10
2 5 10 15
3 8 15 23
Average waiting time = 8.333333
Average turn around time = 16.000000

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -3(b)

Objective: Write a program to implement Shortest Job First (SJF)


Code:

#include <stdio.h>
int main()
{
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");

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


printf("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;
printf("P BT WT TAT\n");

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);
}

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

OUTPUT:

Enter number of process: 3


Enter Burst Time:
P1: 10 P2: 5 P3: 8
P BT WT TAT
P2 5 0 5
P3 8 5 13
P1 10 13 23
Average Waiting Time= 6.000000
Average Turnaround Time= 13.666667

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -3(c)

Objective: Write a program to implement PRIORITY SCHEDULING mechanisms


Algorithm for Priority Scheduling:

Step 1: Start the process.

Step 2: Accept the number of processes in the ready Queue.

Step 3: For each process in the ready Q, assign the process ID and accept the CPU burst time

Step 4: Sort the ready queue according to the priority number.

Step 5: Set the waiting of the first process as ‘0’ and its burst time as its turnaround time.

Step 6: For each process in the Ready Q calculate


A. Waitingtimeforprocess(n)=waitingtimeofprocess(n-1)+Bursttimeofprocess(n-1)
B. Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)

Step 7: Calculate
A. Average waiting time = Total waiting Time / Number of processes
B. Average Turnaround time = Total Turnaround Time / Number of processes

Step 8: Stop the process.

Code:
#include <conio.h>
#include <stdio.h>
void main() {
int i, j, n, tat[10], wt[10], bt[10], pid[10], pr[10], t, twt = 0, ttat = 0;
float awt, atat;
clrscr();
printf("\n-----------PRIORITYSCHEDULING--------------\n");
printf("Enter the No of Process: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
pid[i] = i;
printf("Enter the Burst time of Pid %d : ", i);
scanf("%d", &bt[i]);
printf("Enter the Priority of Pid %d : ", i);
scanf("%d", &pr[i]);
}
// Sorting start
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
if (pr[i] > pr[j]) {
t = pr[i];
pr[i] = pr[j];
pr[j] = t;

t = bt[i];
bt[i] = bt[j];

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

bt[j] = t;

t = pid[i];
pid[i] = pid[j];
pid[j] = t;
}
}

// Sorting finished
tat[0] = bt[0];
wt[0] = 0;
for (i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
tat[i] = wt[i] + bt[i];
}
printf(“n-- ------------------------------------------------------------------”);
printf("Pid\t Priority\tBurst time\tWaitingTime\tTurnArroundTime\n");
printf(“n-- ------------------------------------------------------------------”);
for (i = 0; i < n; i++) {
printf("\n%d\t\t%d\t%d\t\t%d\t\t%d", pid[i], pr[i], bt[i], wt[i], tat[i]);
}
for (i = 0; i < n; i++) {
ttat = ttat + tat[i];
twt = twt + wt|i];
}
awt = (float)twt / n;
atat = (float)ttat / n;
printf("\n\nAvg.Waiting Time: %nAvg.Turn Around Time: %fAn", , awt, atat);
getch();
}

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

OUTPUT:
-----—--------PRIORITY SCHEDULING------—-------

Enter the NoofProcess:


4
Enter the Burst time of Pid 0:2
Enter the Priority of PidO: 3
Enter the Burst time of Pid 1:6
Enter the Priority of Pid1: 2
Enter the Burst time of Pid 2:4
Enter the Priority of Pid2: 1
Enter the Burst time of Pid 3:5
Enter the Priority of Pid3: 7

Avg. Waiting Time: 6.500000


Avg. Turn Around Time: 10.750000

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -3(d)

Objective: Write a program to implement the ROUND ROBIN SCHEDULING mechanism.

Algorithm for RR:

Step 1: Start the process

Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice.

Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time.

Step 4: Calculate the no. of time slices for each process where

No. of time slice for process(n) = burst time process(n)/time slice

Step 5: If the burst time is less than the time slice then the no. of time slices =1.

Step 6: Consider the ready queue is a circular Q, calculate

(a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of process(n-1) +
the time difference in getting the CPU from process(n-1)
(b) Turn around time for process(n) = waiting time of process(n) + burst time of
process(n)+ the time difference in getting CPU fromprocess(n).

Step 7: Calculate

(c) Average waiting time = Total waiting Time / Number ofprocess


(d) Average Turnaround time = Total Turnaround Time / Number ofprocess

Step 8: Stop

Code:
#include <conio.h>
#include <stdio.h>
intz[10], b[10], n, m[50], r, q, e = 0, avg = 0, i, j;
Float f;
main() {
cIrscr();
printf("\n\tJOB SCHEDULING ALGORITHM[RR]");
printf(
"'nlt*******************************************************/n"); printf(
"\nEnter how many jobs:");
scanf("%d", &n);
printf(" \nEnter burst time for corresponding job... \n");
for (i = 1; i <= n; i++) {
printf("\nProcess %d: ", i);
scanf("@d", &b[il);
z[i]=b[il;
printf("\ nENTER THE TIME SLICE VALUE:");
scanf("/d", &q);
rr);

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

average);
getch);
return 0;

rr()
{
int max = 0;
max = b[1];
for (j = 1; j <= n; j++)
if(max<=b[jl)
max=b[j];
if ((max % q) == 0)
r = (max / q);
else
r = (max / q) + 1;
for (i = 1; i <= r; i++) {
printf("\nround %d", i);
for(j = 1; <= n;
j++ ) if (b[j] > 0) {
bll=b[jl-q;
if(b[jl=0)

{
bljl = 10 printf("\nprocess %d is completed", j);
}
else
printf("\process %d remaining time is %d", j,b[jl);
}
}
return 0;
delay(1000);
average)
{
for (i = 1; i <= n; i++) e = 0;
for (j = 1; j <= r; j++) {
if (z[i] != 0)
if(z[il>=q)
{
} else m[ite] = q;
z[i] -= q;
m[ite]=z[il;z[il=0;
} else
e = e + n;
m[i + e] = 0;
}
for (i = 2; i <= n; i++)
for (j = 1; j <= i - 1; j++) avg = avg + mil;
for (i = n + 1; i <= r * n; i++) {
if (m[i] != 0)
1
for(j=i-(n-1);j<=i-1;j++)
avg=m[l+avg;

f=avg/n;
printf("\nTOTAL WATING:%d"
, avg);

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

printi( In nAVERAGE WAITING TIME:%fn", f);


for(i=1;i<=r*n;i++)
{
if (m[i] != 0)
i†(i%n==0K
printf("P%d",(i%n)+(n)); }
elseprintf("p%d", (i
%n));
for(j=1;j<=m[il;j++)
printf("⅑c",22);
}
printf("\n");
return ();

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

OUTPUT:
Enter the number of Processors 4
Enter the Timeslice 5
Enter the process ID 15
Enter the Burst Time for the process10
Enter the process ID 26
Enter the Burst Time for the process 15
Enter the process ID 37
Enter the Burst Time for the process20
Enter the process ID 48
Enter the Burst Time for the process 25

ROUND-ROBIN SCHEDULING ALGORITHM

The average waiting Time=4.2f


The average Turn around Time=4.2f

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

EXPERIMENT -4
Objective: Write a program to implement Banker's algorithm.

THEORY :
The banker's algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety by simulating
the allocation for the predetermined maximum possible amounts of all resources, then makes an "s-state" check to
test for possible activities, before deciding whether allocation should be allowed to continue. Banker's algorithm is
named so because it is used in the banking system to check whether a loan can be sanctioned to a person. Suppose
there are n number of account holders in a bank and the total sum of their money is S. If a person applies for a loan
then the bank subtracts the loan amount from the total cash that bank has and if the remaining amount is greater than
S then only the loan is sanctioned. It is done because if all the account holders come to withdraw their money then
the bank can easily do it.

Code:
#include <stdio.h>
int n, m; // number of processes and resources int available[m]; // available
// resources
int allocation[n][m]; // allocated resources to processes int max|n][m]; //
// maximum resources required by processes
int finish[n]; // finish array
void banker() {
int i, j;
// Initialize finish array
for (i = 0; i < n; i++) {
finish[i] = 0;

// Banker's algorithm
while (1) {
// Find a process p that is not finished and can be allocated resources
int p = -1;
for (i = 0; i < n; i++) {
if (!finish[il) {
int canAllocate = 1;
for (j = 0; j < m; j++) 1
if (max[ilD] - allocation[i]D] > available i]) 1
canAllocate = 0;
break;
}
}
if (canAllocate) {
р = i;
break;
}
}
}
// If no such process exists, the system is in a safe state
if (p == -1) {
break;

// Allocate resources to process p
for (j= 0; j < m; j++) 1
available[il -= allocation [p]Öl;
}

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

finish[p] = 1;
}
}
int main() {
// Initialize number of processes and resources
n = 4;
m = 3;
// Initialize available resources
available[0] = 3;
available[1] = 3;
available[2] = 2;
// Initialize allocation of resources to processes
allocation[0][0] = 0;
allocation[0][1] = 1;
allocation[0][2] = 0;
allocation[11 [0] = 2; allocation[1][1] = 0; allocation[1][2] = 0;
allocation[2][0] = 3; allocation | 2][1] = 0;
allocation[2][2] = 2;
allocation (31[0] = 2;
allocation [3][1] = 1;
allocation[3][2] = 0;
// Initialize maximum resources required by processes
max[0][0] = 7;
max[0][1] = 5;
max[0][2] = 3;
max[1][0] = 3;
max[1][1] = 2;
max[1][2] = 2;
max[2][0] = 2;
max[2][1] = 2;
max[2][2] = 2;
max[3][0] = 4;
max[3][1] = 3;
max[3][2] = 3;
// Banker's algorithm
banker();

// Print the finish array


for (i = 0; i < n; i++) ‹
printf("Process %d: finish = %d\n", i + 1, finish[il);
}
return 0;
}

Uma Shankar IT- 3 2200910130177


Operating System Lab (BCS - 451)

Output:

Process 1: finish =1
Process 2: finish =1
Process 3: finish =1
Process 4: finish =0

Uma Shankar IT- 3 2200910130177

You might also like