30
CHAPTER 2 : PROCESS AND THREADS Derryfianto W / B / 1112034

Chapter 2.1-2.2

Embed Size (px)

DESCRIPTION

system operasi chapter 2.1 sampai 2.2 menenai therea dan proses

Citation preview

Page 1: Chapter 2.1-2.2

CHAPTER 2 : PROCESS AND

THREADS

Derryfianto W / B / 1112034

Page 2: Chapter 2.1-2.2

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.

Page 3: Chapter 2.1-2.2

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.

Page 4: Chapter 2.1-2.2
Page 5: Chapter 2.1-2.2

Process Creation

There are 4 principal events that causes processes to be created:1. System Initialization2. Execution of a process creation system

call by a running process3. A user to create a new process4. Initiation of a batch job

Page 6: Chapter 2.1-2.2

Process Termination

The process will terminate, usually due to one of the following condition:1. Normal Exit2. Error Exit3. Fatal Error4. Killed by another process

Page 7: Chapter 2.1-2.2

Process Hierarchies

In UNIX: All the process in the whole system belong

to a single tree, with init at the root. Processes in UNIX can’t 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.

Page 8: Chapter 2.1-2.2

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)

Page 9: Chapter 2.1-2.2
Page 10: Chapter 2.1-2.2

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.

Page 11: Chapter 2.1-2.2

The other implementation is Interrupt Vector. Interrupt Vector: contains the address of

the interrupt service procedure.

Page 12: Chapter 2.1-2.2

Modeling Multiprogramming

Page 13: Chapter 2.1-2.2

2.2 Threads

Threads: A kind of process within a process. Thread Usage:

1. Decomposing an apllication into multiple sequential threads, so the programming model becomes simpler.

2. Threads are lighter weight than processes, they are easier to create and destroy.

3. Threads can overlap, thus speeding up the application.

4. Threads are useful on systems with multiple CPUs, where real parallelism are possible.

Page 14: Chapter 2.1-2.2

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.

Page 15: Chapter 2.1-2.2

Word Processor

Page 16: Chapter 2.1-2.2

Use In WWW Server

Page 17: Chapter 2.1-2.2

Dispatcher: reads incoming requests for work from the network.

Worker Thread: threads for operating

Page 18: Chapter 2.1-2.2

The Classical Thread Model

Page 19: Chapter 2.1-2.2

a. Would be Used when the three process are essentially unrelated.

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

Page 20: Chapter 2.1-2.2

Each thread will generally call different procedures, so each threads need its own stack.

Page 21: Chapter 2.1-2.2

POSIX Threads

To make it possible to write portable threaded program, IEEE has defined standard called Pthreads.

Page 22: Chapter 2.1-2.2

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 doesn’t 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.

Page 23: Chapter 2.1-2.2
Page 24: Chapter 2.1-2.2

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 can’t be sent to all thread register.

Page 25: Chapter 2.1-2.2

Hybrid Implementation

The kernel is only aware of only the kernel –level threads and schedule those.

Each kernel level-thread has some set of user-level threads that take turns using it.

Page 26: Chapter 2.1-2.2

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.

Page 27: Chapter 2.1-2.2

Pop-Up Threads

A new thread that is created by the system to handle something.

Pop Up Thread don’t 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 kernel’s table and I/O Devices

Page 28: Chapter 2.1-2.2
Page 29: Chapter 2.1-2.2

Making Single Threaded Code Multithreaded

Page 30: Chapter 2.1-2.2