0% found this document useful (0 votes)
34 views

Os Lab File

This practical file summarizes key differences: (a) It compares open source software, freeware, and proprietary software in terms of licensing, collaboration, and examples. (b) It contrasts PC and mobile operating systems regarding user interface, form factor, multitasking, input methods, customization, file management, and updates. (c) It outlines differences between Android and iOS platforms in terms of ownership, ecosystems, app distribution, interfaces, services integration, and development environments.
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)
34 views

Os Lab File

This practical file summarizes key differences: (a) It compares open source software, freeware, and proprietary software in terms of licensing, collaboration, and examples. (b) It contrasts PC and mobile operating systems regarding user interface, form factor, multitasking, input methods, customization, file management, and updates. (c) It outlines differences between Android and iOS platforms in terms of ownership, ecosystems, app distribution, interfaces, services integration, and development environments.
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/ 34

Amity University, Uttar Pradesh

Amity School of Engineering and Technology

B.Tech CSE(IOT and Cybersecurity including BCT)

Practical File

OPERATING SYSTEM
(CSE202)

Submitted to: Submitted By:

Dr. Geetika Chahek Juneja


Department of A023166922062
Computer Science and Engineering 4CSE-IOT(Y-Batch)
INDEX

Exp no Experiment name Date of Date of Signature


allotment checking
Experiment 1

AIM:
(a) Presenting differences among open source software, firmware and proprietary software.

(b) Presenting differences between PC OS and MOBILE OS.

(c) Presenting differences between android and Ios.

Solution:
(a)

1. Open-Source 2. Freeware: 3. Proprietary


Software (OSS): Software:

Definition: Software that Definition: Software that is Definition: Open-source


has its source code made given away for free is known software is the opposite of
publicly available is as freeware. Freeware is proprietary software. To use,
referred to as open-source available for download, use, alter, or distribute the
software. This implies that and sharing without the need software, users normally
anyone can access, alter, for payment. need to buy a license; the
and share the source code. source code is not made
available to the public.
Licenses: Open-source Licensing: Freeware may or Licensing: A licensing
software usually has a may not allow you to alter or agreement outlining the
license that enables share its source code, even terms and restrictions of use
unrestricted use, though it is available for free governs proprietary software.
modification, and usage. Typically, users are Users typically have
distribution. The MIT not granted access to the restricted permissions, and a
underlying code and are free business or individual
License and the GNU
to use the software exactly frequently owns the software.
General Public License as is.
(GPL) are examples of
common open-source
licenses.
Collaboration Among Examples: While some Examples: Proprietary
Developers: Open-source freebies may have open- software includes Adobe
software frequently source elements, others may Photoshop, Microsoft Office,
promotes cooperation and be proprietary, preventing and many other commercial
contributions from a access to the source code. programs.
development community. Basic utility tools and free Microsoft Office, Adobe
antivirus software are two Photoshop, and many
This cooperative approach
examples. commercial applications fall
may result in quicker
into the category of
software invention and. proprietary software.
Enhancement

(b)

PC OS MOBILE OS
User Interface: PC operating systems such User Interface: Mobile operating systems like
as Windows, macOS, and Linux, which are Android and iOS offer user interfaces designed
primarily built for desktop or laptop for fingers, gestures, and smaller screens
environments, provide a desktop interface because they were made for touchscreens and
with a mouse and keyboard as the major smaller displays.
input devices.
Form Factor: designed to enable a wider Form Factor: designed with efficiency,
variety of applications and peripherals on portability, and touch-based interactions in
larger computing devices with more mind, specifically for smaller, more portable
powerful hardware. devices like smartphones and tablets.

Multitasking: Generally offers strong Multitasking: Although multitasking is


multitasking, enabling users to run several supported by current mobile OS versions, the
programs in resizable windows at once. strategy is frequently different, emphasizing
app switching and background activities to
save battery life and resources.
Input Methods: Supports a wide range of Input Methods: Often comes with virtual
peripherals, including printers, scanners, and keyboards and is touch input only. There is
external drives, but is mostly based on minimal support for extra peripherals; portability
keyboards and mouse for input. and convenience are prioritized.

Customization: Usually gives users Customization: In order to preserve security


extensive customization options, ranging and a consistent user experience, mobile OS
from installing a wide range of third-party platforms like iOS may have additional
apps to modifying system settings. restrictions on some areas, even though
customization choices have grown over time.
File Management: Offers a conventional File Management: To make file management
file system with direct file and folder access easier to use, it frequently abstracts it. On
for users. mobile OS platforms, applications often
administer their own file systems, and there
may be restrictions on direct user access.
Updates and Installation: Users can typically Updates and Installation: The OS itself may
install software from a number of sources push updates straight to the device, and
and control updates. centralized app stores are frequently used for
the installation of applications. Users' ability to
manage the updating process might be
restricted.

(c)

Android Ios
Platform ownership: Developed by the Open Platform ownership: Developed and
Handset Alliance, a consortium of companies exclusively owned by Apple. It is a closed-
led by Google. It is an open-source operating source operating system, and only Apple
system, meaning that device manufacturers devices (such as iPhones and iPads) can
can customize it to some extent. run iOS.
Device Ecosystem: Available on a wide range Device Ecosystem: iOS: Exclusive to
of devices from various manufacturers, Apple devices, such as iPhones, iPads, and
including Samsung, Google, Huawei, and iPod Touch. Apple controls both the
many others. There's a diverse ecosystem of hardware and software, providing a more
devices with varying specifications and price unified and controlled user experience.
points.
App Distribution: Apps are primarily App Distribution: Apps are exclusively
distributed through the Google Play Store, but distributed through the Apple App Store,
users can also install apps from other sources and Apple tightly controls the app
(sideloading) if they choose. ecosystem, reviewing and approving each
app before it becomes available to users.
User Interface and Customization: Offers a User Interface and Customization:
high level of customization. Users can Provides a more consistent and controlled
personalize their home screens, use widgets, user interface. Customization options are
and choose from a variety of third-party more limited compared to Android, with a
launchers to modify the look and feel of the focus on simplicity and ease of use.
device.
Integration with Other Services: Tightly Integration with Other Services: :
integrated with Google services, such as Integrated with Apple's ecosystem,
Gmail, Google Drive, and Google Assistant. including iCloud, iMessage, FaceTime,
However, users can also use third-party and Siri. While some third-party services
services seamlessly. are available, the integration with Apple
services is often more seamless.
Fragmentation: Due to its open nature, there Fragmentation: Apple devices generally
is a higher degree of device fragmentation. receive updates simultaneously, and a
Different manufacturers may release updates significant majority of eligible devices get
the latest iOS version shortly after release.
at different times, and some devices may not
receive the latest Android versions
Development Environment: Developed Development Environment: Developed
using Java or Kotlin programming languages. using Swift or Objective-C programming
The Android Studio IDE is the primary languages. The Xcode IDE is the official
development environment. development environment.
Security and Privacy: Offers robust security Security and Privacy: Known for its
features, including app sandboxing and regular strong emphasis on security and privacy.
security updates. Users have more control over Apps are subject to strict review processes,
app permissions. and iOS provides users with detailed
control over app permissions.
Experiment 2

Aim : Use of basic UNIX shell commands / Linux commands.

Software Used : JSLinux

1) ls : It allows you to list the contents of the directory you want (the current directory
by default), including files and other nested directories.

2) alias : The alias command lets you define temporary aliases in your shell
session. When creating an alias, you instruct your shell to replace a word with
a series of commands.

3) unalias : As the name suggests, the unalias command aims to remove an alias from
the already defined aliases.

4) pwd : The pwd command stands for “print working directory,” and it
outputs the absolute path of the directory you’re in.

5) cd : It refers to “change directory” and, as its name suggests, switches you to


the directory you’re trying to access.
6) cp : This is the copy command in Linux.

7) rm : You can use the rm command to remove files and directories.

8) mv : use the mv command to move (or rename) files and directories through your
file system.

9) mkdir : To create folders in the shell, you use the mkdir command. Just specify
the new folder’s name, ensure it doesn’t exist, and you’re ready to go.

10) touch : The touch command allows you to update the access and
modification times of the specified file
11) cat : Cat, short for “concatenate,” lets you create, view, and concatenate files directly
from the terminal. It’s mainly used to preview a file without opening a graphical text
editor.

12) echo : The echo command displays defined text in the terminal

13) ps : With ps, you can take a look at the processes your current shell session is running. It
prints useful information about the programs you’re running, like process ID, TTY
(TeleTYpewriter), time, and command name.

14) passwd : passwd allows you to change the passwords of user accounts.
15) history : If you’re struggling to remember a command, history comes in handy. This
command displays an enumerated list with the commands you’ve used in the past.

16) which : The which command outputs the full path of shell commands. If it can’t
recognize the given command, it’ll throw an error.

17) shred : This command overrides the contents of a file repeatedly, and as a result, the
given file becomes extremely difficult to recover.

18) less : less (opposite of more) is a program that lets you inspect files backward and
forward.
19) tail : Similar to cat, tail prints the contents of a file with one major caveat: It
only outputs the last lines. By default, it prints the last 10 lines, but you can
modify that number with -n.

20) head: This one is complementary to the tail command. head outputs the first 10
lines of a text file, but you can set any number of lines you want to display with
the -n flag.

21) grep : Grep is one of the most powerful utilities for working with text files. It
searches for lines that match a regular expression and print them

22) whoami : The whoami command (short for “who am i”) displays

the username currently in use.


23) wc : Wc stands for “word count,” and as the name suggests, it returns the
number of words in a text file.

24) uname : uname(short for “Unix name”) prints the operative system information.

25) find : The find command searches for files in a directory hierarchy based on a
regex expression.
Experiment 3

Aim: To perform the following.


a) various ways to use CAT command.
b) various ways to use GREP command.
c) various ways to use PIPE operator.
d) Various ways to use SORT command.

Theory/Code/Output:

A) CAT COMMANDS
The cat command in Unix-like operating systems is used to concatenate and
display the content of files. It can be a versatile tool, and here are eight
common ways to use the cat command:

1) Displaying a File:

This command displays the contents of the specified file (filename) on the
terminal.
2) Concatenating Multiple Files:

Concatenate the contents of file1 and file2 and display them on the
terminal.

3) Redirecting Output to a New File:

Redirect the content of file1 to a new file named new file.

4) Appending to an Existing File:

Append the content of file2 to an existing file named existing file.

5) Numbering Lines:

Display the content of filename with line numbers.


6) Displaying Non-Printable Characters:

Display non-printable characters in a visible format.

7) Displaying Tabs as ^I:

Display tabs as ^I in the output.

8) Displaying Line Endings:

Display the content of filename with dollar signs at the end of each
line to indicate line endings.

B) GREP COMMANDS
The grep command is a powerful and flexible tool for searching
text patterns in Unix-like operating systems. Here are various
ways to use the grep command:
1) Basic Search:

This searches for the specified "pattern" in the given file.

2) Case-insensitive Search:

Ignore case distinctions in both the pattern and the input files.

3) Recursive Search:

Recursively search for the pattern in all files within the specified directory.

4) Count Matches:

Display only the count of lines that contain the pattern.

5) Display Line Numbers:

Display line numbers along with the lines containing the pattern.
6) Display Only Matching Part of Lines:

Show only the part of the line that matches the pattern.

7) Invert Match:

Invert the match, i.e., display lines that do not contain the specified
pattern.

8) Recursive Invert Match:

Recursively display lines that do not contain the specified pattern.

C) PIPE OPERATOR:
The pipe (|) operator in Unix-like operating systems is used to combine
the output of one command and use it as the input for another
command. It allows for the creation of powerful command-line
combinations. Here are various ways to use the pipe command:
1) Basic Usage:

This passes the output of command1 as the input to command2.

2) Filtering:

This example uses cat to display the contents of a file and then uses grep
to filter lines containing a specific pattern.

3) Counting Lines:

This counts the number of lines in the file by piping the output of cat
to the wc -l command.

4) Sorting:

This sorts the output of the ls -l command.

5) Combining Multiple Commands:


This example combines the use of ps, grep, and awk to find the process
ID of a specific process.

6) Paging:

The less command allows you to page through the output of ls -l.

7) Redirecting:

This redirects the combined output of command1 and command2 to a


file named output.txt.

8) Calculations:

This example uses the echo command to provide input to the bc


(calculator) command.

D) SORT COMMANDS
The sort command is a powerful utility in Unix-like operating systems for
sorting lines of text files. Here are various ways to use the sort command:

1) Basic Sorting:
This command will display the contents of the file filename sorted in
ascending order based on the first character of each line.

2) Sort and Redirect Output:

his command sorts the contents of the file filename and redirects
the sorted output to a new file named sorted_output.txt.

3) Sort in Descending Order:

he -r option reverses the order of the sort, sorting in descending


order.
4) Sort Numerically:

Use the -n option to sort numerically rather than lexicographically.

5) Sort Unique:
The -u option removes duplicate lines, displaying only unique
lines.
6) Sorting Multiple Files Numerically:

Sort the Data of files only in numerical form.

7) Sorting Multiple Files:

Shows the complete output of the files.


Experiment 4

Aim:
A) Write a program in c/c++ to perform First Come First Serve approach.
B) Write a program in c/c++ to perform Shortest Job First approach.

Software used:
Visual Studios Codes.

Theory:
Simplest CPU scheduling algorithm that schedules according to arrival times
of processes. The first come first serve scheduling algorithm states that the
process that requests the CPU first is allocated the CPU first. It is implemented
by using the FIFO queue.When a process enters the ready queue, its PCB is
linked to the tail of the queue. When the CPU is free, it is allocated to the
process at the head of the queue. The running process is then removed from
the queue. FCFS is a non-preemptive scheduling algorithm.

Algorithm for FCFS Scheduling:


The waiting time for the first process is 0 as it is executed first.
The waiting time for the upcoming process can be calculated by:
wt[i] = ( at[i – 1] + bt[i – 1] + wt[i – 1] ) – at[i]
where :
wt[i] = waiting time of current process
at[i-1] = arrival time of previous process
bt[i-1] = burst time of previous process
wt[i-1] = waiting time of previous process
at[i] = arrival time of current process

Shortest Job First (SJF) is an algorithm in which the process having the smallest
execution time is chosen for the next execution. This scheduling method can
be pre-emptive or non-pre-emptive. It significantly reduces the average waiting
time for other processes awaiting execution. The full form of SJF is Shortest
Job First.

CODE:
A) FCFS
#include<iostream>
using namespace std;
// Process structure to store information about each process
struct Process {
int processId;
int arrivalTime;
int burstTime;
int completionTime;
int turnaroundTime;
int waitingTime;
int responseTime;};
// Function to calculate turnaround time, waiting time, and
completion time
void calculateTimes(Process processes[], int n) {
// Initialization
processes[0].completionTime = processes[0].burstTime;
processes[0].turnaroundTime = processes[0].completionTime
- processes[0].arrivalTime;
processes[0].waitingTime = processes[0].turnaroundTime -
processes[0].burstTime;
processes[0].responseTime = processes[0].waitingTime;
// Calculate times for the rest of the processes
for (int i = 1; i < n; i++) {
processes[i].completionTime = processes[i -
1].completionTime + processes[i].burstTime;
processes[i].turnaroundTime =
processes[i].completionTime - processes[i].arrivalTime;
processes[i].waitingTime =
processes[i].turnaroundTime - processes[i].burstTime;
processes[i].responseTime =
processes[i].waitingTime;}}
// Function to display process details and times
void display(Process processes[], int n) {
cout << "Process\tArrival Time\tBurst Time\tCompletion
Time\tTurnaround Time\tWaiting Time\tResponse Time\n";
for (int i = 0; i < n; i++) {
cout << processes[i].processId << "\t\t" <<
processes[i].arrivalTime << "\t\t" << processes[i].burstTime
<< "\t\t"
<< processes[i].completionTime << "\t\t" <<
processes[i].turnaroundTime << "\t\t" <<
processes[i].waitingTime
<< "\t\t" << processes[i].responseTime <<
endl;}}
int main() {
int n;
// Get the number of processes
cout << "Enter the number of processes: ";
cin >> n;
// Create an array of processes
Process processes[n];
// Input details for each process
for (int i = 0; i < n; i++) {
processes[i].processId = i + 1;
cout << "Enter arrival time for process " << i + 1 <<
": ";
cin >> processes[i].arrivalTime;
cout << "Enter burst time for process " << i + 1 <<
": ";
cin >> processes[i].burstTime;}
/* Sort processes based on arrival time (assuming
processes have arrived in order)
Note: In a real-world scenario, you might need to
implement sorting based on arrival time. Here, we assume that
processes are already in the order of arrival.
Calculate times using FCFS scheduling*/
calculateTimes(processes, n);
// Display process details and times
display(processes, n);
return 0;}

OUTPUT:
B) SJF
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Process {
int id;
int burstTime;
int arrivalTime;
int startTime;
int completionTime;
int turnaroundTime;
int waitingTime;
int responseTime;};
bool compareArrivalTime(const Process& p1, const Process&
p2) {
return p1.arrivalTime < p2.arrivalTime;}
bool compareBurstTime(const Process& p1, const Process& p2)
{
return p1.burstTime < p2.burstTime;}
void calculateTimes(vector<Process>& processes) {
sort(processes.begin(), processes.end(),
compareArrivalTime);
int currentTime = 0;
for (int i = 0; i < processes.size(); ++i) {
if (currentTime < processes[i].arrivalTime) {
currentTime = processes[i].arrivalTime;}
processes[i].startTime = currentTime;
processes[i].completionTime = currentTime +
processes[i].burstTime;
processes[i].turnaroundTime =
processes[i].completionTime - processes[i].arrivalTime;
processes[i].waitingTime =
processes[i].turnaroundTime - processes[i].burstTime;
processes[i].responseTime = processes[i].startTime -
processes[i].arrivalTime;
currentTime = processes[i].completionTime;}}
int main() {
int n;
cout << "Enter the number of processes: ";
cin >> n;
vector<Process> processes(n);
for (int i = 0; i < n; ++i) {
processes[i].id = i + 1;
cout << "Enter arrival time for Process " <<
processes[i].id << ": ";
cin >> processes[i].arrivalTime;
cout << "Enter burst time for Process " <<
processes[i].id << ": ";
cin >> processes[i].burstTime;}
calculateTimes(processes);
cout << "\nProcess\tTurnaround Time\tWaiting
Time\tCompletion Time\tResponse Time\n";
for (const Process& p : processes) {cout << p.id << "\t"
<< p.turnaroundTime << "\t\t" << p.waitingTime << "\t\t" <<
p.completionTime << "\t\t" << p.responseTime << endl;}

return 0;}

OUTPUT:
Experiment 5

Aim: Write a program in c/c++ to perform the shortest job first approach in
a pre-emptive approach.

Software Used: Visual Studios Code.

Theory:
Shortest Job First (SJF) is an algorithm in which the process having the smallest
execution time is chosen for the next execution. This scheduling method can
be pre-emptive or non-pre-emptive. It significantly reduces the average waiting
time for other processes awaiting execution. The full form of SJF is Shortest
Job First.
Preemptive SJF or Shortest Remaining time First(SRTF):
In Preemptive SJF Scheduling, jobs are put into the ready queue as they come.
A process with the shortest burst time begins execution. If a process with even
a shorter burst time arrives, the current process is removed or pre-empted from
execution, and the shorter job is allocated CPU cycle.
Each process is assigned a priority, and the process with the highest priority is
scheduled first. In case of ties, FCFS is often used as a tiebreaker.
A preemptive version of SJF where the scheduler can preemptively switch to a
process with a shorter burst time if it arrives.

Code:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Process {
int id;
int arrivalTime;
int burstTime;
int remainingTime;
};

bool compareArrivalTime(const Process &a, const Process &b)


{
return a.arrivalTime < b.arrivalTime;
}

int main() {
int n; // number of processes
cout << "Enter the number of processes: ";
cin >> n;

vector<Process> processes(n);

// Input process details


for (int i = 0; i < n; ++i) {
processes[i].id = i + 1;
cout << "Enter arrival time for process " << i + 1
<< ": ";
cin >> processes[i].arrivalTime;
cout << "Enter burst time for process " << i + 1 <<
": ";
cin >> processes[i].burstTime;
processes[i].remainingTime = processes[i].burstTime;
}

// Sort processes based on arrival time


sort(processes.begin(), processes.end(),
compareArrivalTime);

int currentTime = 0;
int completedProcesses = 0;

while (completedProcesses < n) {


int shortestRemainingTime = INT_MAX;
int selectedProcess = -1;

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


if (processes[i].arrivalTime <= currentTime &&
processes[i].remainingTime < shortestRemainingTime &&
processes[i].remainingTime > 0) {
shortestRemainingTime =
processes[i].remainingTime;
selectedProcess = i;
}
}

if (selectedProcess == -1) {
// No process is ready to execute at this time
currentTime++;
} else {
// Execute the selected process for 1 time unit
processes[selectedProcess].remainingTime--;
currentTime++;

// If the process is completed


if (processes[selectedProcess].remainingTime ==
0) {
completedProcesses++;
cout << "Process " <<
processes[selectedProcess].id << " completed at time " <<
currentTime << endl;
}
}
}
return 0;
}

Output:

You might also like