24
Sistem Operasi http://fasilkom.narotama.ac.id/ 1 Processes and Threads Lecture 3 3.1. Processes 3.2. Threads

Kcd226 Sistem Operasi Lecture03

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

11

Processes and Threads

Lecture 3

3.1. Processes

3.2. Threads

Page 2: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

22

ProcessesThe Process Model

• Multiprogramming of four programs

• Conceptual model of 4 independent, sequential processes

• Only one program active at any instant

Page 3: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

33

Process Creation

Principal events that cause process creation

1. System initialization

• Execution of a process creation system

1. User request to create a new process

2. Initiation of a batch job

Page 4: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

44

Process Termination

Conditions which terminate processes

1. Normal exit (voluntary)

2. Error exit (voluntary)

3. Fatal error (involuntary)

4. Killed by another process (involuntary)

Page 5: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

55

Process Hierarchies

• Parent creates a child process, child processes

can create its own process

• Forms a hierarchy

– UNIX calls this a "process group"

• Windows has no concept of process hierarchy

– all processes are created equal

Page 6: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

66

Process States (1)

• Possible process states

– running

– blocked

– ready

• Transitions between states shown

Page 7: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

77

Process States (2)

• Lowest layer of process-structured OS

– handles interrupts, scheduling

• Above that layer are sequential processes

Page 8: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

88

Implementation of Processes (1)

Fields of a process table entry

Page 9: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

99

Implementation of Processes (2)

Skeleton of what lowest level of OS does when an interrupt occurs

Page 10: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1010

ThreadsThe Thread Model (1)

(a) Three processes each with one thread

(b) One process with three threads

Page 11: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1111

The Thread Model (2)

• Items shared by all threads in a process

• Items private to each thread

Page 12: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1212

The Thread Model (3)

Each thread has its own stack

Page 13: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1313

Thread Usage (1)

A word processor with three threads

Page 14: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1414

Thread Usage (2)

A multithreaded Web server

Page 15: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1515

Thread Usage (3)

• Rough outline of code for previous slide

(a) Dispatcher thread

(b) Worker thread

Page 16: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1616

Thread Usage (4)

Three ways to construct a server

Page 17: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1717

Implementing Threads in User Space

A user-level threads package

Page 18: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1818

Implementing Threads in the Kernel

A threads package managed by the kernel

Page 19: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

1919

Hybrid Implementations

Multiplexing user-level threads onto kernel-

level threads

Page 20: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

2020

Scheduler Activations

• Goal – mimic functionality of kernel threads

– gain performance of user space threads

• Avoids unnecessary user/kernel transitions

• Kernel assigns virtual processors to each process

– lets runtime system allocate threads to processors

• Problem:Fundamental reliance on kernel (lower layer)

calling procedures in user space (higher layer)

Page 21: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

2121

Pop-Up Threads

• Creation of a new thread when message arrives

(a) before message arrives

(b) after message arrives

Page 22: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

2222

Making Single-Threaded Code Multithreaded (1)

Conflicts between threads over the use of a global variable

Page 23: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

2323

Making Single-Threaded Code Multithreaded (2)

Threads can have private global variables

Page 24: Kcd226 Sistem Operasi Lecture03

Sistem Operasi http://fasilkom.narotama.ac.id/

24

Discussion / Question

24