You are on page 1of 22

CASE STUDY ON

MICROSOFT OPERATING SYSTEM

THE CONTENTS:
I) INTRODUCTION
II) CONCEPT
III) PROCESS TERMINATION
IV) PROCESS STATE
V) PROCESS COMMUNICATION
VI) PROCESS SYNCHRONIZATION
VII) PROCESS SCHEDULING
VIII) DEADLOCK
IX) SUMMARY (MS DOS & MS NT)

SUBMITTED BY:
Adila Rahman Mim – 1720042
Shanta Islam Emu - 1730555
Md.Saif Uddin Buiyan Adal – 1721137
Tahzin Ahmed Silvee - 1721833
INTRODUCTION
What is an Operating System?
An Operating System is a set of programs that controls and coordinates the
use of computer hardware among various application programs. It
provides an environment within which user can execute programs. A
computer can be divided into four components: the hardware, the
operating system, the applications programs, the users. It is the operating
system that manages all the above components. The various functions of
the operating system are:
• Controlling Input/output devices (Keyboard, Mouse, Monitor,
Printer, Plotter etc.)
• Memory and File storage management
• CPU Scheduling and controlling processes
• Loading, initiating, executing and supervising user applications
programs
• Handling errors and restarting
• Providing command interface between the user and computer system

CONCEPT

A process is a program in execution. Process is not as same as program


code but a lot more than it. A process is an 'active' entity as opposed to
program which is considered to be a 'passive' entity. Attributes held by
process include hardware state, memory, CPU etc.
Process memory is divided into four sections for efficient working:

2
• The Text section is made up of the compiled program code, read in
from non-volatile storage when the program is launched.
• The Data section is made up the global and static variables,
allocated and initialized prior to executing the main.
• The Heap is used for the dynamic memory allocation, and is
managed via calls to new, delete, malloc, free, etc.
• The Stack is used for local variables. Space on the stack is reserved
for local variables when they are declared.

PROCESS CREATION
AND
PROCESS TERMINATION
Process Creation and Process termination are used to create and terminate
processes respectively. Details about these are given as follows:

Process Creation
A process may be created in the system for different operations. Some of
the events that lead to process creation are as follows:
• User request for process creation

3
• System Initialization
• Batch job initialization
• Execution of a process creation system call by a running process
A process may be created by another process using fork(). 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 process creation using fork() is as follows:

Process Termination
Processes terminate either voluntarily through an exit system call or
involuntarily as the result of a signal.
Some of the causes of process termination are as follows:
1. A process may be terminated after its execution is naturally
completed. This process leaves the processor and releases all its
resources.
2. A child process may be terminated if its parent process requests for
its termination.
3. A process can be terminated if it tries to use a resource that it is not
allowed to. For example - A process can be terminated for trying to
write into a read only file.
4. If an I/O failure occurs for a process, it can be terminated. For
example - If a process requires the printer and it is not working, then
the process will be terminated.

4
5. In most cases, if a parent process is terminated then its child
processes are also terminated. This is done because the child process
cannot exist without the parent process.
6. If a process requires more memory than is currently available in the
system, then it is terminated because of memory scarcity.
In either case, process termination causes a status code to be returned to
the parent of the terminating process (if the parent still exists). This
termination status is returned through the wait4 system call. The wait4 call
permits an application to request the status of both stopped and terminated
processes. The wait4 request can wait for any direct child of the parent, or
it can wait selectively for a single child process or for only its children in a
particular process group. Wait4 can also request statistics describing the
resource utilization of a terminated child process. Finally, the wait4
interface allows a process to request status codes without blocking.
Within the kernel, a process terminates by calling the exit() routine. The
exit() routine first kills off any other threads associated with the process.
The termination of other threads is done as follows:
• Any thread entering the kernel from userspace will thread_exit()
when it traps into the kernel.
• Any thread already in the kernel and attempting to sleep will return
immediately with EINTR or EAGAIN, which will force them back
out to userspace, freeing resources as they go. When the thread
attempts to return to userspace, it will instead hit exit().
The exit() routine then cleans up the process’s kernel-mode execution state
by doing the following:
• Canceling any pending timers
• Releasing virtual-memory resources
• Closing open descriptors
• Handling stopped or traced child processes
With the kernel-mode state reset, the process is then removed from the list
of active processes—the allproc list—and is placed on the list of zombie
processes pointed to by zombproc. The process state is changed to show
that no thread is currently running. The exit() routine then does the
following:

5
• Records the termination status in the p_xstat field of the process
structure
• Bundles up a copy of the process’s accumulated resource usage (for
accounting purposes) and hangs this structure from the p_ru field of
the process structure
• Notifies the deceased process’s parent
Finally, after the parent has been notified, the cpu_exit() routine frees any
machine-dependent process resources and arranges for a final context
switch from the process.
The wait4 call works by searching a process’s descendant processes for
ones that have entered the ZOMBIE state (e.g., that have terminated). If a
process in ZOMBIE state is found that matches the wait criterion, the
system will copy the termination status from the deceased process. The
process entry then is taken off the zombie list and is freed. Note that
resources used by children of a process are accumulated only as a result of
a wait4 system call. When users are trying to analyze the behavior of a
long-running program, they will find it useful to be able to obtain this
resource usage information before the termination of a process. Although
the information is available inside the kernel and within the context of that
program, there is no interface to request it outside that context until
process termination.

PROCES STATE
Processes in the operating system can be in any of the following states:
• NEW- The process is being created.
• READY- The process is waiting to be assigned to a processor.
• RUNNING- Instructions are being executed.
• WAITING- The process is waiting for some event to occur(such as
an I/O completion or reception of a signal).
• TERMINATED- The process has finished execution.

6
PROCESS COMMUNICATION
The Windows operating system provides mechanisms for facilitating
communications and data sharing between applications. Collectively, the
activities enabled by these mechanisms are called interprocess
communications (IPC).

Inter Process Communication or IPC as name suggests, is used to share


data between two applications or processes. The processes can be on the
same computer or somewhere else in the network. Windows operating
system supports various techniques for IPC, these are:
• Clipboard: A loosely coupled data sharing method. When user uses
copy or cut command in any application/windows, the copied data is
saved in clipboard by windows (temporary storage). The other
application can access the data from the clipboard.
• COM: Component Object Model offers a platform to interact in
Server and Client pattern between processes. COM server can be a
local server or In-Process server. There can be also multiple COM
clients which interact with the COM server and exchange data.

7
• Copy Data: Windows provides a message i.e. WM_COPYDATA
which enables a process to share data with another process. It can be
used with SendMessage API of win32 and COPYDATASTRUCT is
used as a parameter. This message is used in case of local computer
only.
• DDE: Dynamic Data Exchange is a protocol that contains a set of
guidelines and rules to send data across processes. A process can use
SendMessage API with WM_DDE_INITIATE or WM_DDE_ACK
message sent in response to WM_DDE_INITIATE message. It uses
shared memory to exchange data.
• File Mapping: File Mapping, a fast communication mechanism
between processes and gives an efficient way to use the file content
in the virtual memory or by accessing the memory sharing. In this
IPC the data of the file is treated as a part of the address space of the
process so that process can easily access the address of the content.
Any other process with access to the shared memory should
implement synchronization to mitigate the risks of data getting
corrupted. File Mapping is done on the same system/machine and is
not available for network processes.
• Pipes: Pipes can be used as both single and bi-directional data
sharing mechanism. Windows supports two types of pipes i.e. pipe
and anonymous pipe. Anonymous pipes can be used in the same
network or between the related processes only, while named pipe
can be used over a network within different processes. Pipe can be
considered as a FIFO queue where one end acts as a server and other
as the client.
• Mailslot: Mailslot provides only one way communication until users
create multiple mailslots. One process can create a mailslot as server
and the other process create the client mailslot. Mailslot client sends
the message to the mailslot server by writing a message and the
messages are appended to the mailslot server until the server has
read them. A process can have both server and client mailslot and
this helps in multi directional communication. Mailslot provides the
facility to broadcast the message over the network.
• Sockets: Socket is an efficient way to send and receive data over the
network and on the local computer. It uses multiple protocols like

8
TCP/IP and UDP. It is used with the combination of machine IP and
Port address where the data can be transported.
• RPC: Remote Procedure Call provides a way to communicate over
the network so that a process can invoke a function in the other
process. RPC maintains a tightly coupled relationship between the
client and server with high performance.
Once you decide on insertion of IPC in your application then you need to
decide on which IPC you require. Also there are several aspects you need
to think about IPC for local machine or network or IPC will work on same
OS or different operating systems or Performance matters or not.

PROCESS SYNCHRONIZATION
Process Synchronization means sharing system resources by processes in a
such a way that, Concurrent access to shared data is handled thereby
minimizing the chance of inconsistent data. Maintaining data consistency
demands mechanisms to ensure synchronized execution of cooperating
processes.
Process Synchronization was introduced to handle problems that arose
while multiple process executions. Some of the problems are discussed
below.

Critical Section Problem:


A Critical Section is a code segment that accesses shared variables and has
to be executed as an atomic action. It means that in a group of cooperating
processes, at a given point of time, only one process must be executing its
critical section. If any other process also wants to execute its critical
section, it must wait until the first one finishes.

9
Solution to Critical Section Problem:
A solution to the critical section problem must satisfy the following three
conditions:

1. Mutual Exclusion
Out of a group of cooperating processes, only one process can be in its
critical section at a given point of time.
2. Progress
If no process is in its critical section, and if one or more threads want to
execute their critical section then any one of these threads must be allowed
to get into its critical section.3. Bounded Waiting
After a process makes a request for getting into its critical section, there is
a limit for how many other processes can get into their critical section,
before this process's request is granted. So after the limit is reached,
system must grant the process permission to get into its critical section.
Synchronization Hardware:
Many systems provide hardware support for critical section code. The
critical section problem could be solved easily in a single-processor
environment if we could disallow interrupts to occur while a shared
variable or resource is being modified.

10
In this manner, we could be sure that the current sequence of instructions
would be allowed to execute in order without pre-emption. Unfortunately,
this solution is not feasible in a multiprocessor environment.
Disabling interrupt on a multiprocessor environment can be time
consuming as the message is passed to all the processors.
This message transmission lag, delays entry of threads into a critical
section and the system efficiency decreases.
Mutex Locks:
As the synchronization hardware solution is not easy to implement for
everyone, a strict software approach called Mutex Locks was introduced.
In this approach, in the entry section of code, a LOCK is acquired over the
critical resources modified and used inside critical section, and in the exit
section that LOCK is released.
As the resource is locked while a process executes its critical section hence
no other process can access it.
WINDOWS SYNCHRONIZATION
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.

11
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 −

MUTEX dispatcher objects

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.
A general overview of the scheduling is depicted by the below
representation:

Windows process scheduling


1) 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

12
usually called cooperative multitasking. Windows 95 introduced a
rudimentary preemptive scheduler; however, for legacy support opted to
let 16 bit applications run without preemption
2) 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:
7. Give preference to short jobs.
8. Give preference to I/O bound processes.
9. 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.
3) 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 Algorithms
To decide which process to execute first and which process to execute last
to achieve maximum CPU utilisation, computer scientists have defined
some algorithms, they are:
First Come First Serve(FCFS) Scheduling
Shortest-Job-First(SJF) Scheduling
Priority Scheduling
Round Robin(RR) Scheduling
Multilevel Queue Scheduling
Multilevel Feedback Queue Scheduling

13
Deadlock in Operating System
A process in operating systems uses different resources and uses resources
in following way.
1) Requests a resource
2) Use the resource
2) Releases the resource

Deadlock is a situation where a set of processes are blocked because each


process is holding a resource and waiting for another resource acquired by
some other process.

Conditions for Deadlock


Four conditions must hold for there to be a deadlock:
• Mutual exclusion condition: Each resource is either currently
assigned to exactly one process or is available.
• Hold and wait condition: Processes currently holding resources
granted earlier can request new resources.
• No preemption condition: Resources previously granted cannot be
forcibly taken away from a process. They must be explicitly released
by the process holding them.
• Circular wait condition: There must be a circular chain of two or
more processes, each of which is waiting for a resource held by the
next member of the chain.
All four of these conditions must be present for a deadlock to occur. If one
of them is absent, no deadlock is possible.
Methods for handling deadlock:
There are three ways to handle deadlock:
1) Deadlock prevention or avoidance: The idea is to not let the system into
deadlock state.
One can zoom into each category individually, Prevention is done by
negating one of above-mentioned necessary conditions for deadlock.
Avoidance is kind of futuristic in nature. By using strategy of
“Avoidance”, we have to make an assumption. We need to ensure that all
information about resources which process WILL need are known to us
prior to execution of the process. We use Banker’s algorithm (Which is in-
turn a gift from Dijkstra) in order to avoid deadlock.

14
2) Deadlock detection and recovery: Let deadlock occur, then do
preemption to handle it once occurred.
3) Ignore the problem all together: If deadlock is very rare, then let it
happen and reboot the system. This is the approach that both Windows and
UNIX take.
Deadlock Recovery:
A traditional operating system such as Windows doesn’t deal with
deadlock recovery as it is time and space consuming process. Real-time
operating systems use Deadlock recovery.

CHECKING WHETHER THE WINDOWS


EXPERIENCE DEADLOCK

Procedure:
1. Download the windbg tool and retain its default settings.
2. Download path:
o Windows 32–bit: Download the tool from the official website
or obtain it from a legal channel.
o Windows 64–bit: Download the tool from the official website
or obtain it from a legal channel.
3. Start the windbg tool.
4. Click File, and select Symbol Search Path.
5. The Symbol Search Path dialog box is displayed.
6. In the Symbol Search Path dialog box, enter the following
information, and click OK, as shown in Figure 1.
7. SRV*Local path where the symbol file is
stored*http://msdl.microsoft.com/download/symbols

15
Figure 1 Symbol Search Path

8. Click File, and choose Open Crash Dump to open the generated
memory dump file to be analyzed.
9. In the command input box in the lower part, enter the following
command to query the lock information of the operating system:
10. !locks
11. Check the command output to confirm whether thread
deadlock occurs.
o If yes, go to 8.
o If no, contact technical support.
12.Run the following command to check which process the thread
belongs to:
12. !thread Thread name
For example, if the process of thread 85062af8 is queried, the following
command output is displayed:
kd> !thread 85062af8THREAD 85062af8 Cid 0288.1878 Teb:
7ffdd000 Win32Thread: fd98cdd8 WAIT: (WrResource) KernelMode
Non-Alertable85f10098 SynchronizationEventNot
impersonatingDeviceMap 8d008980Owning Process 86b57d40 Image:
winlogon.exeAttached Process N/A Image: N/AWait Start TickCount
6216029 Ticks: 154 (0:00:00:02.406)Context Switch Count
460UserTime 00:00:00.000KernelTime 00:00:00.015
13. Image indicates the name of the process that the thread
belongs to.

16
14. Check the software and vendor of the process based on the
process name.
o For operating system processes or software, contact Microsoft
technical support.
o For PV Driver software, contact technical support.
o For third-party software, contact the technical support of the
third-party vendor.

SUMMARY:
MS DOS:
MS-DOS is a single-user, single-process operating system. Due to
confinement of device-independent code into lone layer, porting of MS-
DOS is theoretically reduced to writing of the BIOS code for the new
hardware. Although early versions of MSDOS show resemblance to the
CP/M operating system, later releases of MS-DOS have Unix-like
features. At the command level, MS-DOS provides a hierarchical file
system, 1/0 redirection, pipes and filters. User-written commands can be
invoked in the same way as standard system commands, thus giving the
appearance of extending the basic system functionality. Lesson No. 1
Intro. to Operating System 295 MS-DOS provides both device-dependent
and device-independent versions of system calls for input/output and file
manipulation. Being a single-user system, MSDOS provides only
rudimentary file protection and access control. Disk space is allocated in
terms of clusters of consecutive sectors. A variant of chaining that allows
for relatively fast random access to files is used for keeping track of both
file blocks and free space.
MS WINDOWS NT:
Microsoft designed NT to be an extensible, portable operating system, able
to take advantage of new techniques and hardware. NT supports multiple
operating environments and symmetric multiprocessing. The use of kernel
objects to provide basic services, and the support for client-server
computing, enable NT to support a wide variety of application
environments. For instance, NT can run programs compiled for MS-DOS,
Win16, Windows 95, NT, and POSIX. It provides virtual memory,

17
integrated caching, and preemptive scheduling. NT supports a security
model stronger than those of previous Microsoft operating systems, and
includes Lesson No. 1 Intro. to Operating System 324 internationalization
features. NT runs on a wide variety of computers, so users can choose and
upgrade hardware to match their budgets and performance requirements,
without needing to alter the applications that they run.

Windows is by far the most popular proprietary personal computer


operating system.

Let’s view why;

• Process:
No inherent parent/child relationship

• Threads:
Basic scheduling unit
Fibers – cooperative user-mode threads

• Windowing:
Windows has a kernel-mode Windowing subsystem.

18
• Higher priorities are favored:
Priorities of dynamic threads get boosted on wakeups
Thread priorities are never lowered

• Most threads run in variable priority levels:


Priorities 1-15;
A newly created thread starts with a base priority
Threads that complete I/O operations experience priority boost (but
never higher than 15)
A thread’s priority will never be below base priority

• The Windows API function SetThreadPriority() sets the priority


value for a specified thread
This value, together with the priority class of the thread’s process,
determines the thread’s base priority level
Windows will dynamically adjust priorities for non-real-time threads

• Real time scheduling in windows.


Windows XP supports static round-robin scheduling policy for threads
with priorities in real-time range (16-31)
Threads run for up to one quantum.
Quantum is reset to full turn on preemption.
Priorities never get boosted.

• RT threads can starve important system services such as


CSRSS.EXE
Se-Increase Base Priority Privilege is required to elevate a thread’s priority
into real-time range.

19
• Windows NT has always had an O (1) scheduler based on pre-sorted
thread priority queues.

• In windows (vista sp1) the time-slice varies -manual (user setting,


window boost) as well as automatic (window boost).

• In windows (vista sp1) CPU partitioning is not possible.

REFERENCES:
https://support.huawei.com/onlinetoolsweb/Troublesolving/re
s/projectmaterialsEn/cloud_computing/FusionAccess13/vmstu
ck_task_005.html
http://www.informit.com/articles/article.aspx?p=25193
https://technet.microsoft.com/en-us/ff543668(v=vs.96)
https://docs.microsoft.com/en-us/windows-
hardware/drivers/devtest/deadlock-detection
https://www.geeksforgeeks.org/deadlock-detection-recovery/
https://www.geeksforgeeks.org/introduction-of-deadlock-in-
operating-system/
https://www.studytonight.com/operating-system/cpu-
scheduling
https://www.tutorialspoint.com/operating_system/os_process_
scheduling.htm
https://www.ukessays.com/essays/information-
systems/compare-cpu-scheduling-of-linux-and-windows.php
https://www.microsoftpressstore.com/articles/article.aspx?p=2
233328&seqNum=7

20
https://www.studytonight.com/operating-system/process-
synchronization
https://www.studytonight.com/operating-system/introduction-
to-semaphores
https://www.tenouk.com/ModuleV.html
https://www.tutorialspoint.com/process-synchronization-in-
windows
https://www.tenouk.com/ModuleT4.html
https://docs.microsoft.com/en-
us/windows/win32/procthread/terminating-a-process
https://www.britannica.com/technology/operating-system
https://www.britannica.com/technology/MS-DOS
https://en.wikibooks.org/wiki/Operating_System_Design/Case
_studies

21
22

You might also like