Os Lab File
Os Lab File
Practical File
OPERATING SYSTEM
(CSE202)
AIM:
(a) Presenting differences among open source software, firmware and proprietary software.
Solution:
(a)
(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.
(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
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.
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
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
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.
5) Numbering Lines:
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:
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 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.
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:
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:
6) Paging:
The less command allows you to page through the output of ls -l.
7) Redirecting:
8) Calculations:
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.
his command sorts the contents of the file filename and redirects
the sorted output to a new file named sorted_output.txt.
5) Sort Unique:
The -u option removes duplicate lines, displaying only unique
lines.
6) Sorting Multiple Files Numerically:
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.
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.
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>
struct Process {
int id;
int arrivalTime;
int burstTime;
int remainingTime;
};
int main() {
int n; // number of processes
cout << "Enter the number of processes: ";
cin >> n;
vector<Process> processes(n);
int currentTime = 0;
int completedProcesses = 0;
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++;
Output: