Operating System LAB: Project - 2

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

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Total Marks:

Obtained Marks:

Operating System
LAB

Project - 2

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Student Name: Muddasir Ali

Reg. Number: 1880154

Submitted to: Adil Majeed

Windows:-
Definition:-
Windows is a licensed operating system and its source code is inaccessible. It is
designed for business owners, other commercial user and even individuals with no
computer programming knowledge. It is simple and straightforward to use.

Windows offers features like,

 Multiple operating environments


 Symmetric multiprocessing
 Client-server computing
 Integrated caching
 Virtual memory
 Portability
 Extensibility
 Preemptive scheduling

The first version of Windows, known as Windows 1.0, revealed in 1985 following
the formation of Microsoft. It was based upon the MS-DOS core. Following that

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

initial launch, new versions of Windows were quickly rolled out. This included the
first major update in 1987 and Windows 3.0 in the same year.

In 1995, perhaps the most widely used version yet, Windows 95 was born. At this
point, it ran on a 16-bit DOS-based kernel and 32-bit users-space to enhance the
user experience.

Linux:-

Definition: -

Linux is a free and open-source operating system based on Unix standards which
provides a programming interface as well as user interface compatibility. It also
contains many separately developed elements, free from proprietary code.

The traditional monolithic kernel is employed in the Linux kernel for performance


purposes. Its modular feature allows most drivers to dynamically load and unload at
run time.

Linux was created by Finnish student Linus Torvalds, who wanted to create a free
operating system kernel that anyone could use. It was launched much later than
Windows, in 1991. Although it still was regarded as a very bare bones operating
system, without a graphical interface like Windows. With just a few lines of source
code in its original release to where it stands today, containing more than 23.3
million lines of the source code, Linux has surely grown considerably.

Linux was first distributed under GNU General Public License in 1992.

Comparison between Linux and Windows:-

Questions on the topics:


a. Interprocess Communication
The following interprocess communication methods are provided by
both Linux and Windows 10:

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

i. Socket
ii. Pipe
iii. Memory---mapped file Suppose you have to transfer several files
and directories from one computer to the other.
i. Which of the above methods would you use if both computers are
running the Linux operating system? Provide justification for
your answer.
Answer:-
The socket is a mechanism that provides a connection between the two-
processor system by using network stacks. In a more clear way, we can use
sockets to communicate and transfer data between two systems.
Following are advantages of socket
 Provides flexible access to files and data over a network.
 Sharing resources.
 Security.
 Speed.
 Centralized software management.
 Provide security like sending sensitive (password protected) files and
programs on a network.
Therefore we use socket in to transfer files and directories.

i. Which of the above methods would you use if both computers are
running the
Windows 10 operating system? Provide justification for your
answer.
Answer:-

We used pipes to transfer files and directories from one computer to other
computer. There are two types of pipes for two-way communication: anonymous
pipes and named pipes. We used Named pipes are used to transfer data between
processes that are not related processes and between processes on different

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

computers. Typically, a named-pipe server process creates a named pipe with a


well-known name or a name that is to be communicated to its clients. A named-pipe
client process that knows the name of the pipe can open its other end, subject to
access restrictions specified by named-pipe server process. After both the server
and client have connected to the pipe, they can exchange data by performing read
and write operations on the pipe.

 Inter-process Communication in Windows:-

The Windows operating system provides mechanisms for facilitating


communications and data sharing between applications. Collectively, the activities
enabled by these mechanisms are called inter-process communication (IPC). Some
forms of IPC facilitate the division of labor among several specialized processes.
Other forms of IPC facilitate the division of labor among computers on a network.

Typically, applications can use IPC categorized as clients or servers. A client is an


application or a process that requests a service from some other application or
process. A server is an application or a process that responds to a client request.
Many applications act as both a client and a server, depending on the situation. For
example, a word processing application might act as a client in requesting a
summary table of manufacturing costs from a spreadsheet application acting as a
server. The spreadsheet application, in turn, might act as a client in requesting the
latest inventory levels from an automated inventory control application.

After we decide that our application would benefit from IPC, you must decide
which of the available IPC methods to use. It is likely that an application will use
several IPC mechanisms. The answers to these questions determine whether an
application can benefit by using one or more IPC mechanisms.

 Should the application be able to communicate with other applications


running on other computers on a network, or is it sufficient for the application
to communicate only with applications on the local computer?
 Should the application be able to communicate with applications running on
other computers that may be running under different operating systems (such
as 16-bit Windows or UNIX)?

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

 Should the user of the application have to choose the other applications with
which the application communicates, or can the application implicitly find its
cooperating partners?
 Should the application communicate with many different applications in a
general way, such as allowing cut-and-paste operations with any other
application, or should its communications requirements be limited to a
restricted set of interactions with specific other applications?
 Is performance a critical aspect of the application? All IPC mechanisms
include some amount of overhead.
 Should the application be a GUI application or a console application? Some
IPC mechanisms require a GUI application.

The following IPC mechanisms are supported by Windows:

 Clipboard
 COM
 Data Copy
 DDE
 File Mapping
 Mail-slots
 Pipes
 RPC
 Windows Sockets

 Inter-process communication in Linux:-

Inter process communication (IPC) is used for exchanging data between multiple
threads in one or more processes or programs. The Processes may be running on
single or multiple computers connected by a network. The full form of IPC is Inter-
process communication.

It is a set of programming interface which allow a programmer to coordinate


activities among various program processes which can run concurrently in an

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

operating system. This allows a specific program to handle many user requests at
the same time.

PC is very important to the design process for microkernels and nano kernels,


which reduce the number of functionalities provided by the kernel. Those
functionalities are then obtained by communicating with servers via IPC, leading to
a large increase in communication when compared to a regular monolithic kernel.
IPC interfaces generally encompass variable analytic framework structures. These
processes ensure compatibility between the multi-vector protocols upon which IPC
models rely

Inter-process communication in linux is supported by both of mechanisms such as

 message queue,
 shared memory
 semaphore
 pipes

. CPU Scheduling
Suppose that you are listening to an audio file, making a presentation,
and downloading some large files from the Internet. How does the
operating system schedule these processes if you are running?
i. Linux
ii. Windows 10

Hint: Consider the type of each process (interactive, real---time, or


background). Also, take into account the different parameters each OS
uses in scheduling.

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

CPU scheduling:-
Scheduling basically deals with the selection of a process that exists in the memory
and ready to execute. The selected process is allocated with the CPU. This function
is performed by the CPU scheduler. The CPU scheduler makes a sequence of
“moves” that determines the interleaving of threads.

 Programs use synchronization to prevent “bad moves”.


 …but otherwise scheduling choices appear (to the program) to be
nondeterministic.

The scheduler’s moves are dictated by a scheduling policy.

Scheduling In windows:-

 Windows 3.1 xs used a non-preemptive scheduler, meaning that it did not


interrupt programs. It relied on the program to end or tell the OS that it
didn’t need processor so that it could move on to another process. This is
usually called cooperative multitasking. Windows 95 introduced a
rudimentary preemptive scheduler; however, for legacy support opted to let
16 bit applications run without preemption
 NT-based versions of Windows use a CPU scheduler based on a multilevel
feedback queue, with 32 priority levels defined. It is intended to meet the
following design requirements for multimode systems:

1. Give preference to short jobs.


2. Give preference to I/O bound processes.
3. Quickly establish the nature of a process and schedule the process
accordingly.

All processes receive a priority boost after a wait event, but processes that have
experienced a keyboard I/O wait get a larger boost than those that have experienced
a disk I/O wait.

“Foreground” processes given higher priority.

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

 Windows XP uses a quantum-based, preemptive priority scheduling


algorithm. The scheduler was modified in Windows Vista to use the cycle
counter register of modern processors to keep track of exactly how many
CPU cycles a thread has executed, rather than just using an interval-timer
interrupt routine.

Scheduling In Linux:-

From versions 2.6 to 2.6.23, the kernel used an O (1) scheduler. The Completely
Fair Scheduler is the name of a task scheduler which was merged into the 2.6.23
release of the Linux kernel. It handles CPU resource allocation for executing
processes, and aims to maximize overall CPU utilization while maximizing
interactive performance. It uses that uses red-black trees instead of queues.

Two classes of processes:

 real-time (soft deadlines)


 timesharing algorithm

Normal process scheduling uses a prioritized, preemptive, credit-based policy:

 Scheduler always chooses process with the most credits to run.


 On each timer interrupt one credit is deducted until zero is reached at which
time the process is preempted.
 If no ready process then all credits for a process calculated as credits =
credits/2 + priority.
 This approach favors I/O bound processes which do not use up their credits
when they run.

The Round Robin and FIFO scheduling algorithms are used to switch between real-
time processes

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Synchronization
Consider a banking system with two functions: deposit (amount) and
withdraw (amount). Both functions are passed the amount that is to be
deposited or withdrawn from a bank account. Assume that a husband
and his wife share the same bank account and concurrently the husband
calls the withdraw() function and the wife calls the deposit () function.

Classify this real world problem among the well---known


synchronization problems. Describe how a race condition is possible.
Propose a synchronization mechanism to prevent the race condition
from occurring for each of the following operating systems. Provide
justification for your choices.
i. Linux
ii. Windows 10

Synchronization in windows:-
Windows operating system is a multithreaded kernel that provide support for real
time application and multiprocessors. On uniprocessor system, Windows provides
interrupt masks to protect access to global resources. It protects access to global
resource using spinlock. The kernel uses spinlocks only to protect short code
segment like Solaris. The kernel ensures that while holding a spinlock, a thread will
never be preempted.
Windows provide dispatcher object for thread synchronization according to several
different mechanisms including mutexes, semaphores, events and timers. The
system protects shared data by requiring a thread to gain ownership of a mutex for
accessing the data and when it is finished, releases the ownership.
Events acts as a conditional variable to notify a waiting thread when desired
condition occurs.
Timers are used to notify one or more thread when time expired.
Dispatcher objects may be either signaled state or a non-signaled state.

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Signaled state indicates that an object is available and a thread will not block when
acquiring the object.

Non-signaled state indicates that an object is not available and a thread will block
when trying to acquire the object.
The below figure shows the state transitions of a mutex lock dispatcher object −

Synchronization in linux:-
Process synchronization in Linux involves providing a time slice for each process
so that they get the required time for execution.
The process can be created using the fork() command in Linux. The creating
process is called the parent process and the created process is the child process. A
child process can have only one parent but a parent process may have many
children. Both the parent and child processes have the same memory image, open
files and environment strings. However, they have distinct address spaces.
A diagram that demonstrates the fork() command is given as follows −

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

. Memory Management

If two processes from a database program want to share memory, what


methods are available to allow them to do so in Windows 10 and Linux? If
more than one method is available for this purpose in either operating
system, then choose the best option. Provide justification for your choice
Memory Management in windows vs linux:-
Introduction

Important concepts of memory management and compared the memory


management system of windows and Linux.

 The memory management system is one of the important parts of the


operating system.
 Its basic function is to manage the memory hierarchy of RAM and secondary
memory devices.
 There is always a need of more memory than physical memory. Memory
management allows this to be done through the concept of virtual memory.
 Virtual memory can be many times larger than the physical memory.
 The most important task of memory management includes allocation and
dealloacation of memory to the processes.

Memory management system provides:

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

1. Large Address Space


2. Protection
3. Memory Mapping
4. Physical Memory Allocation for Processes
5. Shared Virtual Memory.

Comparison

1) Data structures

Windows

 Windows uses tree data structure.


 Each node of the tree is called Virtual Address Descriptors (VAD).
 VAD marks each node as free, committed or reserved.
 Committed nodes are those nodes that are currently being used.
 Free nodes are unused nodes.
 Reserved nodes cannot be used until reservation is lifted off.

Linux

 It uses linked list data structure.


 It maintains a list of vm_area_structs.
 This list is searched whenever a page is to be found.
 It also records the range of address, protection mode and the direction in
which it grows (up or down).
 If number of entries becomes more than 32, Linux converts linked list into a
tree.
 Linux uses data structure depending upon the situation.

2) Distribution of Process Address Space

Windows

 Windows on 32 bit x86 systems can access up to 4GB of physical memory.


 Windows allows each process to have its own 4GB logical address space by
using paging.

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

 The upper 2GB is kept for windows kernel mode.


 The lower 2GB of the address space is reserved for user mode.

Linux

 3GB of memory space is reserved for user mode


 1GB is kept for Kernel mode.

3) Paging

Linux uses demand paging with no pre paging

 Linux do not swap the entire process instead uses a lazy swapper.
 It never swaps a page into the memory unless that page is needed.
 Instead of swapping in a whole process, the pager swaps only necessary
pages into memory.
 It thus avoids reading pages that will not be used, this decreases swap time
and amount of physical memory required.
 To distinguish between the pages that are in memory and are on the disk we
use valid and non valid bits.
 If bit is valid it shows that the page is legal and is in the memory and if bit is
set to invalid it indicates that it is on the disk.

Linux uses three level paging

Windows uses cluster demand paging

 Pages are brought in the memory when they are needed.


 Instead of bringing pages one by one, eight pages are brought in the memory
simultaneously.
 It makes use of working set model.
 Working set is the amount of memory currently assigned to the process.
 It contains the pages that are in the main memory.
 Size of working set can be changed accordingly.

Windows uses Two Level Paging

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

4) Address structure

Linux

Linear address is broken into four parts:

 Global Directory.
 Middle Directory.
 Page Table
 Offset.

Windows

Address is divided into two parts:

 Page number
 Page offset

5) Page replacement

Linux uses LRU

 Least Recently Used Page Replacement Algorithm (L.R.U.)


 The page that is not used for a long period of time is selected as victim page
and is replaced.
 Implemented in two ways- Counters and stack.
 In counters, each page table entry is associated with a time-of-use field. The
page with smallest time value is replaced.
 In stack, the page at the bottom is removed and put on the top of the stack.
Least recently used is always at the bottom of the stack.

Here is an example of LRU page replacement algorithm.

No. of page faults=12

Windows uses FIFO

OS System BSSE-4/A SZABIST-ISB


Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

 First in First out Page Replacement Algorithm (F.I.F.O.).


 The oldest page is chosen for replacement.
 It suffers from be lady’s anomaly.
 Page fault rate may increase when we increase number of frame.
 It has low performance.
 It has maximum number of page faults.

Here is an example of FIFO page replacement algorithm.

No. of page faults =155)

Windows divides virtual pages into four lists:-

 Modified Page List.


 Stand-by Page List.
 Free Page List.
 Zeroed Page List.

Pages that have been modified are in modified page list. After writing to disk they
are stored in standby list. Pages that have not been modified go to stand by list. The
modified page list is called dirty list and standby list is called clean list.

Linux divides the pages into four lists:-

 Active List.
 Inactive-dirty List.
 Inactive clean List.
 Free List.

OS System BSSE-4/A SZABIST-ISB

You might also like