Sie sind auf Seite 1von 30

CHAPTER 2 :

PROCESS AND
THREADS
Derryfianto W / B / 1112034

2.1 Process

Process: an instance of an executing


program,
including the current
values of the
program
counter, registers, variables.

Many process are secretly started,


when the system is booted.

The Process Model

All the runnable software on the


computer, including the OS, is organized
into a number of sequential processes.
Multiprogramming: the CPU switches
back and forth from process to process.

Process Creation
There are 4 principal events that causes
processes to be created:
1. System Initialization
2. Execution of a process creation system
call by a running process
3. A user to create a new process
4. Initiation of a batch job

Process Termination
The process will terminate, usually due to
one of the following condition:
1. Normal Exit
2. Error Exit
3. Fatal Error
4. Killed by another process

Process Hierarchies

In UNIX:

All the process in the whole system belong


to a single tree, with init at the root.
Processes in UNIX cant disinherit their
children.

In Windows:

No concept of process Hierarchy.


All process are equal.
The parent has a special token(Handle) to
control the child.

Process States
The three states a process may be in:
1. Running (actually using CPU at the
instant)
2. Ready (runnable; temporarily stopped
to let another process run)
3. Blocked(unable to run until some
external event happens)

Implementation of Process
To implement the process model, the OS
maintain a Process Table, with one entry
per process.

This entry contains important info about


the process state.

The other implementation is Interrupt


Vector.

Interrupt Vector: contains the address of


the interrupt service procedure.

Modeling Multiprogramming

2.2 Threads

Threads: A kind of process within a process.


Thread Usage:
1.

2.

3.

4.

Decomposing an apllication into multiple


sequential threads, so the programming model
becomes simpler.
Threads are lighter weight than processes, they
are easier to create and destroy.
Threads can overlap, thus speeding up the
application.
Threads are useful on systems with multiple
CPUs, where real parallelism are possible.

Threads Usage
Many Word Processor three threads.
It is because the third thread can handle
the disk backups without interfering with
the other two.
Having three threads instead of three
processes, they share a common memory
and thus all have access.

Word Processor

Use In WWW Server

Dispatcher: reads incoming requests for


work from
the network.
Worker Thread: threads for operating

The Classical Thread Model

a.

b.

Would be Used when the three process


are essentially unrelated.
Would be appropriate when the three
threads are actually part of the same
job and are actively and closely
cooperating with each other

Each thread will generally call different


procedures, so each threads need its own
stack.

POSIX Threads

To make it possible to write portable


threaded program, IEEE has defined
standard called Pthreads.

Implementing Thread in
User Space

Threads Package is put entirely in the user


space.
The kernel knows nothing.
Each process needs its own private thread table
(+):

can be implemented on an operating system that


doesnt support threads.
Allow each process to have its own customized
scheduling algorithm.

(-):

No other thread in that process will ever run unless


the first thread voluntary gives up the CPU.

Implementing Threads in the Kernel

Has a thread table that keeps track of all


the threads in the system.
Thread Table is only put in Kernel Space.
(+)

Better than Users-Level threads

(-)

Slower than User-Level Thread


Signal cant be sent to all thread register.

Hybrid Implementation

The kernel is only aware of only the


kernel level threads and schedule
those.
Each kernel level-thread has some set of

Scheduler Activation

Mimic the functionality of kernel threads,


but with better performance and greater
flexibility like User Space.
Achieved by avoiding unnecessary
transitions between user and kernel
space.

Pop-Up Threads

A new thread that is created by the


system to handle something.
Pop Up Thread dont have any history
that must be restored.
Pop-Up Thread running in the Kernel
Space is usually faster and easier than in
User Space.
Running in kernel space can easily
access all the kernels table and I/O
Devices

Making Single Threaded Code


Multithreaded

Das könnte Ihnen auch gefallen