Top Banner
Rushdi Shams, Dept of CSE, KUET 1 “There are 10 types of people in the world- who understands binary and who does not”
31

Lecture 1 and 2 processes

Sep 12, 2014

Download

Education

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 1 and 2  processes

Rushdi Shams, Dept of CSE, KUET 1

“There are 10 types of people in the world- who understands binary and who does not”

Page 2: Lecture 1 and 2  processes

Process Concept Process is a program in execution; process

execution must progress in sequential fashion A process includes:1. Text Section: Program code. Text files have a

program code which is different than program codes of E-mail programs

2. Program counter: Represents the current state of the process

3. Stack: Contains temporary data like method parameters, return addresses

4. Data section: Contains global variables

Rushdi Shams, Dept of CSE, KUET 2

Page 3: Lecture 1 and 2  processes

Process State

As a process executes, it changes state. This state is noticed by the program counter.new: The process is being createdrunning: Instructions are being executedwaiting: The process is waiting for some event to

occurready: The process is waiting to be assigned to a

processorterminated: The process has finished execution

Rushdi Shams, Dept of CSE, KUET 3

Page 4: Lecture 1 and 2  processes

Diagram of Process State

Rushdi Shams, Dept of CSE, KUET 4

Page 5: Lecture 1 and 2  processes

Process Control Block (PCB)

Information associated with eachprocess Process state Program counter CPU registers CPU scheduling information Memory-management information I/O status information

Rushdi Shams, Dept of CSE, KUET 5

Page 6: Lecture 1 and 2  processes

Process Control Block (PCB)

6Rushdi Shams, Dept of CSE, KUET

Page 7: Lecture 1 and 2  processes

CPU Switch From Process to Process

7Rushdi Shams, Dept of CSE, KUET

Page 8: Lecture 1 and 2  processes

Process Scheduling Queues

Job queue – set of all processes in the system

Ready queue – set of all processes residing in main memory, ready and waiting to execute

Device queues – set of processes waiting for an I/O device

Processes migrate among the various queues

Rushdi Shams, Dept of CSE, KUET 8

Page 9: Lecture 1 and 2  processes

Representation of Process Scheduling

9Rushdi Shams, Dept of CSE, KUET

Page 10: Lecture 1 and 2  processes

Schedulers Long-term scheduler (or job

scheduler) – selects which processes should be brought into the ready queue

Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU

Rushdi Shams, Dept of CSE, KUET 10

Page 11: Lecture 1 and 2  processes

Schedulers (Cont.) Short-term scheduler is invoked very

frequently milliseconds must be fast

Long-term scheduler is invoked very infrequently seconds, minutesmay be slow

The long-term scheduler controls the degree of multiprogramming

Rushdi Shams, Dept of CSE, KUET 11

Page 12: Lecture 1 and 2  processes

Mathematics! If a process is required 10 milliseconds to be

decided for a GO and it takes 100 milliseconds to execute then the CPU usage for that particular task is-

110 ms process requires 10 ms to be decided1 ms process requires 10/110 ms to be decided100 ms process requires ??? ms to be decided

9% of the CPU was used to accomplish that process

Rushdi Shams, Dept of CSE, KUET 12

Page 13: Lecture 1 and 2  processes

Mathematics! If a process is required 100 seconds to be

decided for a GO and it takes 1000 seconds to execute then the CPU usage for that particular task is-

1100 s process requires 100 s to be decided1 s process requires 100/1100 s to be decided100 s process requires ??? s to be decided

9% of the CPU was used to accomplish that process

Rushdi Shams, Dept of CSE, KUET 13

Page 14: Lecture 1 and 2  processes

Mathematics!

Which process should be scheduled by Long term scheduler? Justify your statement

Rushdi Shams, Dept of CSE, KUET 14

Page 15: Lecture 1 and 2  processes

The Process Model

Conceptually, each process has its own virtual CPU

In reality, the real CPU switches back and forth from process to process

This procedure is called pseudoparallelism.

Rushdi Shams, Dept of CSE, KUET 15

Page 16: Lecture 1 and 2  processes

Process A

Process B

Process C

Process D

Rushdi Shams, Dept of CSE, KUET 16

Page 17: Lecture 1 and 2  processes

Process A Process B Process C Process D

Rushdi Shams, Dept of CSE, KUET 17

Page 18: Lecture 1 and 2  processes

A Computer Engineer is making cake today.

In his kitchen, he has a book- “how to bake cake”

He also has ingredients like- flour, baking soda, custard powder, etc.

Rushdi Shams, Dept of CSE, KUET 18

Page 19: Lecture 1 and 2  processes

The book is the program (algorithm) The computer engineer is the CPU The ingredients are input data

(remember global and local variables??) The process is the activity consisting of

our baker reading the book, fetching the ingredient and baking the cake!

Rushdi Shams, Dept of CSE, KUET 19

Page 20: Lecture 1 and 2  processes

Now, his youngest son came to the kitchen

He alleged to his father that he has been attacked by cockroaches and they had a bite on him!

His father stops baking The computer engineer took the first aid

box and aided his son

Rushdi Shams, Dept of CSE, KUET 20

Page 21: Lecture 1 and 2  processes

The son is the interrupt program The first aid box is a different program The injection, medicines in the box are

data need to run the program And of course, aiding son is more high

prioritized process than baking cakes! The engineer after aiding his son comes

back to the kitchen and then again bakes cakes!

Rushdi Shams, Dept of CSE, KUET 21

Page 22: Lecture 1 and 2  processes

Process Creation

Three principal reasons for which a process is created.

1. System initialization

when the OS is booted, several processes are created. Some of them are foreground processes, others are background processes.

Rushdi Shams, Dept of CSE, KUET 22

Page 23: Lecture 1 and 2  processes

Background processes designed to deal with incoming mails sleep. Whenever a mail comes, they wake.

Processes that stay in background to handle some activity like email, web pages, printing are called Daemons.

Rushdi Shams, Dept of CSE, KUET 23

Page 24: Lecture 1 and 2  processes

Process Creation

2. Process created by other process

mostly done by system calls. In network sharing, one process may collect the stream of bytes and store them, other maintains the buffer while introduced by the first one.

Rushdi Shams, Dept of CSE, KUET 24

Page 25: Lecture 1 and 2  processes

Process Creation

3. Process created by a user request

Whatever you click and do on Windows platform, with every single click, there is a possibility to create a new thread!!

Rushdi Shams, Dept of CSE, KUET 25

Page 26: Lecture 1 and 2  processes

Process Creation In UNIX, there is only one system call to

create new process: FORK This call creates an exact clone of the

calling process. After the FORK, two processes- child and

parent have the same memory image, environment strings, same everything!

The child process then executes EXECVE to change its memory image and run a new program

Rushdi Shams, Dept of CSE, KUET 26

Page 27: Lecture 1 and 2  processes

Process Creation The reason for this two step process is

like a reservation in bus ticket. The OS is alerted that with the procedure. Secondly, the child process gets plenty of time to decide whether it’s going to purchase or decline that ticket!

Windows does not have such FORKING. It uses CreateProcess system call and the child is created straight away!

Rushdi Shams, Dept of CSE, KUET 27

Page 28: Lecture 1 and 2  processes

Process Termination

Sooner or later the new process will terminate-

1. Normal Exit (voluntary)

Simply, when you close a window on Windows, the process(es) related to it have their normal exit

Rushdi Shams, Dept of CSE, KUET 28

Page 29: Lecture 1 and 2  processes

Process Termination

2. Error Exit (voluntary) How many times your compiler

reported error to you during compiling? Screen oriented platforms like

Windows, however, uses a hybrid of Normal Exit and Error Exit in such cases!

Rushdi Shams, Dept of CSE, KUET 29

Page 30: Lecture 1 and 2  processes

Process Termination

3. Fatal Error (Non-voluntary)

this error is caused by the process itself, normally due to the program bug. Referencing non-existing memory location or divide by zero problems cause such errors and process termination

Rushdi Shams, Dept of CSE, KUET 30

Page 31: Lecture 1 and 2  processes

Process Termination

4. Killed by another processIn UNIX, the system call is KILL. In Windows, the call is TerminateProcess. In both cases, the KILLER must have the proper authorization to kill the KILLEE.

In some systems, when a process terminates, all processes it creates die. UNIX and Windows-none of them works in this fashion.

Rushdi Shams, Dept of CSE, KUET 31