sistem operasi - raharjo.staff.telkomuniversity.ac.id · definition : process process is an...

23
Sistem Operasi Week 2.1

Upload: doancong

Post on 08-Apr-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Sistem Operasi

Week 2.1

Process Concept

An operating system executes a variety of programs:

1) Batch system – jobs

https://www.youtube.com/watch?v=DyNIt8uagVQ

2) Time-shared systems – user programs or tasks

http://www.cs.berkeley.edu/~brewer/cs262/unix.pdf

HTOP - https://upload.wikimedia.org/wikipedia/commons/b/b1/Htop.png

Batch Processhttps://www.youtube.com/watch?v=DyNIt8uagVQ

Time-Shared

Definition : Process

● Process is an instance (object) of a computer program

that is being executed.

● It contains the program code and its current activity.

● Depending on the operating system (OS), a process may

be made up of multiple threads of execution that execute

instructions concurrently.

Multiple parts of Process

1) The program code, also called text section

2) Current activity including program counter, processor

registers

3) Stack containing temporary data

4) Function parameters, return addresses, local variables

5) Data section containing global variables

6) Heap containing memory dynamically allocated during

run time

Continue……...

1) Program is passive entity stored on disk (executable

file), process is active

2) Program becomes process when executable file

loaded into memory

3) Execution of program started via GUI mouse clicks,

command line entry of its name, etc

4) One program can be several processes

5) Consider multiple users executing the same program

Process in Visual

Disks

Program ProcessClicked

Memory

Process

Process

Process

Process

ProcessSingle User

Have

Multiple User :

````` ` ` ` `

Process State

As a process executes, it changes state

1)NEW: The process is being created

2)RUNNING: Instructions are being executed

3)WAITING: The process is waiting for some event to occur

4)READY: The process is waiting to be assigned to a

processor

5)TERMINATED: The process has finished execution

State & Description

1 New

The process is being created.

2 Ready

The process is waiting to be assigned to a processor. Ready processes are waiting to have the

processor allocated to them by the operating system so that they can run.

3 Running

Process instructions are being executed (i.e. The process that is currently being executed).

4 Waiting

The process is waiting for some event to occur (such as the completion of an I/O operation).

5 Terminated

The process has finished execution.

Animated Versionhttps://courses.cs.vt.edu/csonline/OS/Lessons/Processes/ProcessStateDiagram.swf

Process Control Block (PCB)

Information & Description1 PointerPointer points to another process control block and used for maintaining the scheduling list.2 Process StateProcess state may be new, ready, running, waiting and so on.3 Program CounterProgram Counter indicates the address of the next instruction to be executed for this process.4 CPU registersCPU registers include general purpose register, stack pointers, index registers and accumulators etc. number of register and type of register totally depends upon the computer architecture.5 Memory management informationThis information may include the value of base and limit registers, the page tables, or the segment tables depending on the memory system used by the operating system.This information is useful for de-allocating the memory when the process terminates.6 Accounting informationThis information includes the amount of CPU and real time used, time limits, job or process numbers, account numbers etc.7 I/O status informationI/O devices allocated to process, list of open files

CPU Switch From Process to Process

Animated Versionhttp://cs.uttyler.edu/Faculty/Rainwater/COSC3355/Animations/Switch.swf

Process Scheduling

● Maximize CPU use, quickly switch processes onto CPU for time sharing

● Process scheduler selects among available processes for next execution on CPU

● Maintains scheduling queues of processes– 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

Ready Queue And Various I/O Device Queues

Schedulers

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

– Sometimes the only scheduler in a system

– Short-term scheduler is invoked frequently (milliseconds) (must be fast)

● Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue

– Long-term scheduler is invoked infrequently (seconds, minutes) (may be slow)

– The long-term scheduler controls the degree of multiprogramming● Processes can be described as either:

– I/O-bound process – spends more time doing I/O than computations, many short CPU bursts

– CPU-bound process – spends more time doing computations; few very long CPU bursts

● Long-term scheduler strives for good process mix

Addition of Medium Term Scheduling

Medium-term scheduler can be added if degree of multiple programming needs to decrease

Remove process from memory, store on disk, bring back in from disk to continue execution: swapping

Context Switch

● When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch

● Context of a process represented in the PCB● Context-switch time is overhead; the system does no

useful work while switching– The more complex the OS and the PCB the

longer the context switch● Time dependent on hardware support

– Some hardware provides multiple sets of registers per CPU multiple contexts loaded at once

Operations on Processes

● System must provide mechanisms for:– process creation,– process termination, – and so on as detailed next

Terima Kasih