Chapter 3 (Lecture 9) Operating System by Ihap El-Galaly
Chapter 3 (Lecture 9) Operating System by Ihap El-Galaly
•A web browser might have one thread display images or text while
another thread retrieves data from the network.
•A word processor may have a thread for displaying graphics, another
thread for responding to keystrokes from the user, and a third thread for
performing spelling and grammar checking in the background.
A thread includes a thread ID, a program counter (PC), a register set,
and a stack. It shares with other threads belonging to the same process
its code section, data section, and other OS resources like open files
and signals.
traditional process has a single thread of control. If a process has
multiple threads of control, it can perform more than one task at a time.
Advantages of Multithreading
1.Responsiveness. Multithreading an interactive application may allow
a program to continue running even if part of it is blocked or is
performing a lengthy operation, thereby increasing responsiveness to
the user.
2.Resource sharing. Threads share the memory and the resources of
the process to which they belong by default.
3.Economy. Allocating memory and resources for process creation is
costly. Because threads share the resources of the process to which
they belong, it is more economical to create and context-switch threads.
4.Scalability. The benefits of multithreading can be even greater in a
multiprocessor architecture, where threads may be running in parallel
on different processing cores.
parent is the process that created it; its children are any
processes that it creates. Its siblings are children with the same parent
process).
•An I/O-bound process is one that spends more of its time doing I/O
than it spends doing computations.
•A CPU-bound process, in contrast, generates I/O requests
infrequently, using more of its time doing computations.
Maintains scheduling queues of processes:
•Ready queue – set of all processes residing in main memory, ready
and waiting to execute. This queue is generally stored as a linked list.
•Wait queues – set of processes waiting for an event (e.g. I/O
completion).
ueues throughout its lifetime.
•Process creation.
•Process termination.
Parent process create children processes, which, in turn create other
processes, forming a tree of processes.
process
identifier (pid) (i.e. it is an integer number).
A child process may obtain its resources directly from the OS, or it may
be constrained to a subset of the resources of the parent process.
Resource sharing options:
•Parent and children share all resources.
•Children share subset of parent’s resources.
•Parent and child share no resources.
options:
•The parent continues to execute concurrently with its children.
•The parent waits until some or all of its children have terminated.
-space possibilities for the new process:
•The child process is a duplicate of the parent process (it has the same
program and data as the parent).
•The child process has a new program loaded into it.
Inter-process Communication
-process with 3 different types of
processes:
•Browser process manages user interface, disk and network I/O.
•If one website crashes, only its renderer process is affected; all other
processes remain unharmed.
sandbox,
independent or cooperating.
•A process is independent if it does not share data with any other
processes executing in the system.
•A cooperating process can affect or be affected by other processes
executing in the system, including sharing data.
•Information sharing: several applications may be interested in the
same piece of information.
•Computation speedup: In multicore systems, we may break a task (to
run faster) into subtasks, each of which will be executing in parallel with
the others.
•Modularity: A software system is constructed in a modular fashion,
dividing the system functions into separate processes or threads.
interprocess communication (IPC)
mechanism that will allow them to exchange data
•Shared memory.
that is shared by the cooperating processes is
established. Processes can then exchange information by reading and
writing data to the shared region.
•Message passing.
variables.
•It is particularly useful in a distributed environment, where the
communicating processes may reside on different computers connected
by a network.
IPC facility provides two operations:
•send(message)
•receive(message)
The message (sent by a process) size is either fixed or variable.
•Shared memory.
•Hardware bus.
•Network.
Indirect Communication
mailboxes (also
referred to as ports):
•Each mailbox has a unique identification (id).
receive() from A.
•Who gets the message? Which process will receive the message sent
by P1? The answer depends on which of the following methods we
choose.
Null message.
–consumer problem becomes trivial when
we use blocking send() and receive() statements.
message is available.
Buffering
number.
–server architecture.
specified port.
•Connection-oriented (TCP)
•Connectionless (UDP)
•MulticastSocket class– data can be sent to multiple recipients