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

Full Os 53

The document is a laboratory manual for the Operating Systems course (SEIT2230) at P P Savani School of Engineering, detailing practical assignments completed by student Nakum Rutik D. It includes various programming tasks such as swapping numbers, finding prime numbers, calculating factorials, and simulating CPU scheduling algorithms. Additionally, it covers disk scheduling algorithms and provides source codes for each practical task.

Uploaded by

robbyhaxed
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 views26 pages

Full Os 53

The document is a laboratory manual for the Operating Systems course (SEIT2230) at P P Savani School of Engineering, detailing practical assignments completed by student Nakum Rutik D. It includes various programming tasks such as swapping numbers, finding prime numbers, calculating factorials, and simulating CPU scheduling algorithms. Additionally, it covers disk scheduling algorithms and provides source codes for each practical task.

Uploaded by

robbyhaxed
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/ 26

School of LABORATORY MANUAL

Engineering
Department of Information Technology Engineering

OPERATING SYSTEM
(SEIT2230) | B. Tech.

Name of Student: NAKUM RUTIK D.

Enrollment No.: 23SEO2CB053 Academic Year: 2024-2025


P P Savani School of
Engineering

This is to certify that

Mr./Ms. NAKUM RUTIK D.

of Engineering

having Enrollment No. 23SE02CB053 has completed

his/her Term work in the subject of


OPERATING SYSTEM
(SEIT2230).

Marks Obtained: out of

Sign of Faculty Sign of Head of Department

Date: Date: _________________


23SE02CB053 NAKUM RUTIK D.

PRACTICAL - 1

AIM: SWAPPING OF TWO NUMBERS SOURCE CODE:


#include <stdio.h>

int main(){
int A, B;

printf("ENTER NUMBER A:");


scanf("%d",&A); printf("ENTER NUMBER B:");
scanf("\n%d", &B);
A=A+B;
B=A-B; A=A-B; printf("Swapped Number:
%d",A); printf("\nSwapped Number: %d",B);
}
OUTPUT:

AIM: FINDING PRIME NUMBERS UPTO THE GIVEN NUMBER:


SOURCE CODE:
#include <stdio.h>
OUTPUT:
23SE02CB053 NAKUM RUTIK D.

int main() {
int i,j,o,p;

printf("Enter the Number:"); scanf("%d",&i);


printf("Prime number upto %d are:\n",i);

for(j=2;j<=i;j++)
{ p=0;

for(o=2;o<=j-1;o++)
{
if(j%o==0){ p++;
}
}
if(p==0){ printf("%d\n",j);
}
} return 0;
}

Practical - 2

AIM: FINDING FACTORIAL OF A GIVEN NUMBER: SOURCE


CODE:
#include <stdio.h>

int main() { int n;


long long factorial = 1;

printf("Enter a number: ");


scanf("%d", &n);

if (n < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
23SE02CB053 NAKUM RUTIK D.

for (int i = 1; i <= n; i++) {


factorial *= i;
}

printf("Factorial of %d = %lld\n", n, factorial);


}

return 0;
}
OUTPUT:
23SE02CB053 NAKUM RUTIK D.

You make a new directory via mkdir newdirectoryname. You can remove a
directory using rmdir directoryname. To remove a directory, you must first
remove all the files it contains. To change directories to a directory that is
contained in the current directory use cd directoryname.

. cat stands for “concatenate” and is primarily used to read, display, and
concatenate text files.
Cat a.txt to print
Cat >> a.txt to read

To remove the file rm used

Cp command to copy the file to another file


Cp a.txt(previous file) b.txt (another file)
23SE02CB053 NAKUM RUTIK D.

Echo to print only given message

Pwd is to show location of current working directory.

Touch to make new file in which data is not saved


23SE02CB053 NAKUM RUTIK D.

PRACTICAL 3
AIM: ADDITION OF TWO NUMBERS. SOURCE CODE:
echo "Enter number 1" read a echo "Enter
number 2" read b c=$((a+b)) echo "sum of
numbers are: $c"
OUTPUT:

AIM: SUBTRACTION OF TWO NUMBERS., SOURCE CODE:


echo "Enter number 1" read a echo "Enter number 2" read b
c=$((a-b)) echo "SUBTRACTION of numbers are: $c"
OUTPUT:

AIM: AVERAGE OF TWO NUMBERS. SOURCE CODE:


echo "Enter number 1" read a echo
"Enter number 2" read b c=$(((a+b)/2))
echo "AVERAGE of numbers are: $c"

AIM: PERCENTAGE OF TWO NUMBERS. SOURCE CODE:


echo "Enter number 1" read a echo
"Enter number 2" read b
c=$(((a*100/(a+b))))

echo "percentage of numbers are: $c"


23SE02CB053 NAKUM RUTIK D.

OUTPUT:

AIM: SWAPING OF TWO NUMBERS SOURCE CODE:


echo "Enter number a" read a echo
"Enter number b" read b c=$a a=$b b=$c

echo "swaped numbers are: $a" echo "swaped


numbers are: $b"
OUTPUT:

AIM:
SOURCE DODE:
echo "Hello World"; echo "Enter number
a" read a echo "Enter number b" read b
echo "Enter number c" read c
if [[ $a -gt $b && $a -gt $c ]] then echo "a:$a is
greatest" elif [[ $b -gt $a && $b -gt $c ]]
then echo "b:$b is greatest" else echo
"c:$c is gratest" fi
OUTPUT:

AIM: CHECK THE NUMBER WITH IS GREATER. SOURCE CODE:


23SE02CB053 NAKUM RUTIK D.

echo "Enter number a"


read a if [ $a -gt 0 ] then echo "a is
positive"
elif [ $a -eq 0 ] then echo "a is 0" else
echo "a is negative"
fi
OUTPUT:

AIM: DESIGN CALCULATOR SOURCE CODE:


echo "Enter Number 1" read a echo
"Enter Number 2" read b
echo "Menu : "
echo -e "Enter 1 for Addition\nEnter 2 for Subtraction\nEnter
3 for Multiplication\nEnter 4 for Division" read choice if [
$choice -eq 1 ] then c=$((a+b)) elif [ $choice -eq 2 ]
then c=$((a-b)) elif [ $choice -eq 3 ]
then c=$((a*b)) elif [ $choice -eq 4 ]
then c=$((a/b)) fi
echo "Answer is $c "
OUTPUT:
23SE02CB053 NAKUM RUTIK D.
Practical 4.2

1)Simulate Non Preemptive SJF CPU Scheduling Algorithm

#include <stdio.h>

int main() {
int bt[20], p[20], wt[20], tat[20], i, j, n, total = 0, totalT = 0, pos, temp;
float avg_wt, avg_tat;

printf("Enter number of processes: ");


scanf("%d", &n);

printf("\nEnter Burst Time:\n");


for (i = 0; i < n; i++) {
printf("p%d: ", i + 1);
scanf("%d", &bt[i]); p[i] = i
+ 1;
}
for (i = 0; i < n; i++) {
pos = i; for (j = i + 1; j <
n; j++) { if (bt[j] <
bt[pos]) { pos = j;
}
} temp =
bt[i]; bt[i] =
bt[pos]; bt[pos]
= temp; temp =
p[i]; p[i] =
p[pos]; p[pos]
= temp;
}
tat[0] = bt[0]; totalT +=
tat[0]; for (i = 1; i < n;
i++) { tat[i] = tat[i - 1]
+ bt[i]; totalT += tat[i];
}
for (i = 0; i < n; i++) {
wt[i] = tat[i] - bt[i];
total += wt[i];
}
avg_wt = (float)total / n;
printf("\nProcess | Burst Time | Turnaround Time | Waiting Time"); for (i
= 0; i < n; i++) {
printf("\np%d\t\t | %d\t\t | %d\t\t\t | %d", p[i], bt[i], tat[i], wt[i]);
}
avg_tat = (float)totalT / n;
printf("\n\nAverage Waiting Time = %f", avg_wt);
printf("\nAverage Turnaround Time = %f", avg_tat);

return 0;
}
Practical - 5.1
Q-Simulate Worst-Fit Algorithm for Contiguous Memory Allocation
Answer: #include <stdio.h>
#include <stdlib.h>
#define MAX 25

void worstFit(int blockSize[], int m, int processSize[], int n)


{
int allocation[n]; for
(int i = 0; i < n; i++)
allocation[i] = -1;
for (int i = 0; i < n;
i++)
{ int wstIdx
= -1;
for (int j = 0; j < m; j++)
{
if (blockSize[j] >= processSize[i])
{
if (wstIdx == -1 || blockSize[wstIdx] < blockSize[j])
wstIdx = j;
}
}
if (wstIdx != -1)
{
allocation[i] = wstIdx;

blockSize[wstIdx] -= processSize[i];
}
}
printf("\nProcess No.\tProcess Size\tBlock No.\n");
for (int i = 0; i < n; i++)
{
printf("%d\t\t%d\t\t", i+1, processSize[i]);
if (allocation[i] != -1)
printf("%d\n", allocation[i] + 1);
else
printf("Not Allocated\n");
}
}
int main()
{
int blockSize[MAX], processSize[MAX];
int m, n;
printf("Enter the number of blocks: ");
scanf("%d", &m); printf("Enter the
sizes of the blocks:\n"); for (int i = 0; i
< m; i++) scanf("%d",
&blockSize[i]);

printf("Enter the number of processes: ");


scanf("%d", &n);
printf("Enter the sizes of the processes:\n");
for (int i = 0; i < n; i++)
scanf("%d", &processSize[i]);

worstFit(blockSize, m, processSize, n);


return
0;
}
Output:

Practical - 7.1

Simulate the FIFO (First-In-First-Out) page


replacement algorithm with a given page reference
string. Ans:
a=input("enter pages: ")
inp=[] for i in a:
inp.append(i)
print(inp)
numframe=3 def
fifo(inp,numframe):
frames=[]
fault=0
for i in inp: if i
not in frames:
fault+=1 if
len(frames)==numframe:
frames.pop(0)
frames.append(i) print(f"the current
pages are: {frames}")
print(f" the total faults are: {fault}")

fifo(inp,numframe)

Output:

Operating System
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

PRACTICAL 7.2
Simulate the Least Recently Used (LRU)/Optimal page replacement algorithm with a
page reference string.

CODE:
#include<stdio.h>
#include<limits.h> int n;
int checkHit(int incomingPage, int queue[], int occupied){

for(int i = 0; i < occupied; i++){


if(incomingPage == queue[i])
return 1;
}

return 0;
}

void printFrame(int queue[], int occupied)


{
for(int i = 0; i < occupied; i++)
printf("%d\t\t\t",queue[i]);
}

int main()
{
int incomingStream[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};
n= sizeof(incomingStream)/sizeof(incomingStream[0]);
int frames = 3; int queue[n]; int distance[n]; int
occupied = 0; int pagefault = 0;

printf("Page\t Frame1 \t Frame2 \t Frame3\n");

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


{
printf("%d: \t\t",incomingStream[i]);
// what if currently in frame 7
// next item that appears also 7
// didnt write condition for HIT

if(checkHit(incomingStream[i], queue, occupied)){


printFrame(queue, occupied);
}
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM
// filling when frame(s) is/are empty
else if(occupied < frames){
queue[occupied] = incomingStream[i];
pagefault++;
occupied++;

printFrame(queue, occupied);
}
else{

int max = INT_MIN;


int index;
// get LRU distance for each item in frame
for (int j = 0; j < frames; j++)
{
distance[j] = 0;
// traverse in reverse direction to find
// at what distance frame item occurred last
for(int k = i - 1; k >= 0; k--)
{
++distance[j];

if(queue[j] == incomingStream[k])
break;
}

// find frame item with max distance for LRU


// also notes the index of frame item in queue
// which appears furthest(max distance)
if(distance[j] > max){
max = distance[j];
index = j;
}
}
queue[index] = incomingStream[i];
printFrame(queue, occupied);
pagefault++;
}

printf("\n");
}

printf("Page Fault: %d",pagefault);


23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM
return 0;
}

OUTPUT:
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

PRATICAL 8.1
Simulate the First-Come-First-Serve (FCFS) disk scheduling algorithm, calculate
seek #me, and compare with other algorithms.

CODE:

start = 100 req = [55, 58, 60, 70, 18, 150, 160, 184]

def fcfs(s, q): return sum(abs(s := r) - s + r for r in q)

def ss2(s, q): q = q[:]; t = 0

while q:

r = min(q, key=lambda x: abs(x - s)) t +=

abs(s - r); s = r; q.remove(r) return t

def scan(s, q):

q = sorted(q); l = [r for r in q if r < s]; r = [r for r in q if r >= s] t = sum(abs(s := x) - s

+ x for x in r) if l: t += abs(s - l[-1]); t += sum(abs(s := x) - s + x for x in reversed(l[:-1]))

return t

def look(s, q):

q = sorted(q); l = [r for r in q if r < s]; r = [r for r in q if r >= s] t = sum(abs(s := x) - s + x for

x in r) + sum(abs(s := x) - s + x for x in reversed(l)) return t

PARI PATEL
OPERATING SYSTEM 23SE02IE058

1
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

print("FCFS:", fcfs(start, req)) print("SSTF:",

ss2(start, req)) print("SCAN:", scan(start, req))

print("LOOK:", look(start, req))

OUTPUT

2
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

PRATICAL 8.2
Simulate SCAN Disk Scheduling Algorithm

CODE:

start = 100 requests = [55, 58, 60, 70, 18, 150, 160, 184]

def scan(start, req): req = sorted(req) le* =

[r for r in req if r < start] right = [r for r in req

if r >= start] total = 0 # Go right first for r

in right: total += abs(start - r) start = r

# Then reverse to le* for r in

reversed(le*): total += abs(start -

r) start = r return total

print("SCAN Total Seek Time:", scan(start, requests))

OUTPUT:

Short Report on Operating Systems in


Industries: Security Features, Protection
Mechanisms, and Role-
Based Access Control

3
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

Introduction

Operating systems (OS) serve as the backbone of computing environments across various industries,
providing essential services and security features that protect sensitive data and ensure operational
integrity. This report explores the implementation of OS security in banking, healthcare, and cloud
computing, focusing on protection mechanisms and Role-Based Access Control (RBAC).

OS Security Concepts

Protection Mechanisms

Protection mechanisms in operating systems are designed to safeguard data and resources from
unauthorized access and misuse. Key protection mechanisms include:

1. Access Control Lists (ACLs): Define permissions for users and groups on files and resources.

2. User Authentication: Verifies the identity of users through passwords, biometrics, or multi-factor
authentication.

3. Encryption: Protects data at rest and in transit, ensuring confidentiality and integrity.

4. Sandboxing: Isolates applications to prevent them from affecting each other or the OS.

Role-Based Access Control (RBAC)

RBAC is a security paradigm that restricts system access to authorized users based on their roles
within an organization. Roles are defined according to job functions, and permissions are assigned to
these roles rather than individual users, simplifying management and enhancing security.

Industry Case Studies

Banking

In the banking sector, OS security is paramount due to the sensitive nature of financial data. Banks
utilize robust operating systems like Linux and Windows Server, implementing security features such
as:

4
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

• Multi-Factor Authentication (MFA): Enhances user authentication processes.

• Encryption: Protects customer data and transaction details.

• RBAC: Employees are assigned roles such as teller, manager, or auditor, each with specific access rights
to financial systems and data.

For example, JPMorgan Chase employs a combination of Windows and Linux servers, utilizing RBAC
to ensure that only authorized personnel can access sensitive financial information.

Healthcare

The healthcare industry is heavily regulated, requiring stringent data protection measures to comply
with laws like HIPAA. Operating systems in this sector often include:

• Access Control Mechanisms: Ensuring that only authorized healthcare professionals can access
patient records.
• Audit Trails: Monitoring access to sensitive data to detect unauthorized attempts.

• RBAC: Roles such as doctor, nurse, and administrative staff are defined, with access tailored to their
specific needs.

A notable example is the use of Linux-based systems in electronic health record (EHR) management,
where RBAC is critical in protecting patient information while allowing necessary access for treatment.

Cloud Computing

Cloud computing platforms, such as AWS and Azure, rely on OS security to protect data across shared
environments. Key features include:
• Virtualization Security: Isolating virtual machines to prevent cross-VM attacks.

• Identity and Access Management (IAM): Implementing RBAC to manage user permissions across
cloud resources.
• Data Encryption: Ensuring data is encrypted both at rest and in transit.

For instance, AWS employs a layered security model that includes RBAC through IAM, allowing
organizations to define user roles and permissions for accessing cloud resources.

Analysis of Protection Mechanisms

Windows vs. Linux vs. Cloud-Based OS

• Windows: Offers extensive security features, including BitLocker for disk encryption, Windows Defender
for malware protection, and Group Policy for managing user permissions. RBAC is implemented through
Active Directory.

5
23SE02CB053 SEIT2230
RUTIK NAKUM OPERATING SYSTEM

• Linux: Known for its robust security model, Linux provides SELinux and AppArmor for mandatory access
control, along with traditional RBAC. Its open-source nature allows for extensive customization and
security auditing.

• Cloud-Based OS: Security in cloud environments is often more complex due to multitenancy. Providers
implement strong encryption, IAM, and continuous monitoring to protect data. RBAC is crucial for
managing access across diverse user roles.

Real-World Example: AWS IAM

Amazon Web Services (AWS) Identity and Access Management (IAM) is a prime example of OS
security implementation in cloud computing. IAM allows organizations to create and manage AWS
users and groups, assigning permissions based on roles. This RBAC model ensures that users have
the minimum necessary access to perform their jobs, significantly reducing the risk of data breaches.

Conclusion

Operating systems play a critical role in securing sensitive data across various industries. By
implementing robust protection mechanisms and RBAC, organizations can effectively manage access
and protect against unauthorized use. The case studies in banking, healthcare, and cloud computing
illustrate the importance of OS security in maintaining data integrity and compliance with regulatory
standards. As technology evolves, the need for advanced security measures will continue to grow,
making OS security a vital area of focus for all industries.

You might also like