Sunteți pe pagina 1din 26

IFD20403 - Operating System

Process Management I
Sohail Khan

sohail@unikl.edu.my
http://csrdu.org/sohail
Universiti Kuala Lumpur (UniKL)
Kuala Lumpur, Malaysia

INTRODUCTION




Process Concept
Process Scheduling
Operations on Processes

Process Management I

Sohail (http://csrdu.org/sohail)

2 / 26

PROCESS CONCEPTS



What to call all the CPU activities?


An operating system executes a variety of programs:

Batch system executes jobs


Time-shared systems user programs or tasks

Textbook uses the terms job and process almost interchangeably

Process Management I

Sohail (http://csrdu.org/sohail)

3 / 26

PROCESS CONCEPTS


Process a program in execution

(COND.)

process execution must progress in sequential fashion

It requires certain resources such as CPU time, memory, files, and


I/O devices to accomplish its task.

These resources are allocated to the process either when it is created


or while it is executing.

Process Management I

Sohail (http://csrdu.org/sohail)

4 / 26

PROCESS



A process is the unit of work in most systems.


System consist of a collection of processes:
Operating system processes execute system code,
and user processes execute user code.
All these processes may execute concurrently.

A process includes:

current activities program counter, and content of processors

registers...
stack temporary data (parameter, local variable...)
data section global variables, text section program code
may also include a heap memory that is dynamically allocated
during process runtime


Process vs. Program active vs. passive entities


Process Management I

Sohail (http://csrdu.org/sohail)

5 / 26

PROCESS

IN

MEMORY

Process Management I

Sohail (http://csrdu.org/sohail)

6 / 26

PROCESS STATE


As a process executes, it changes state


new: The process is being created (put in job queue)
ready: The process is waiting to be assigned to a processor (put in
ready queue)
running: Instructions are being executed

waiting: The process is waiting for some event to occur (put in waiting
queues)
terminated: The process has finished execution

It is important to realize that only one process can be running on any


processor at any instant

Process Management I

Sohail (http://csrdu.org/sohail)

7 / 26

PROCESS STATES

New

admitted

interrupt

Ready

exit

Terminated

Running
scheduler
dispatch

I/O or
event
completion

Process Management I

Waiting

I/O or
event
wait

Sohail (http://csrdu.org/sohail)

8 / 26

PROCESS CONTROL BLOCK (PCB)




Each process is represented in the OS by a Process Control Block


(PCB) also known as task control block

PCB contains information associated with each process


Process state i.e. new, ready, running, waiting
Program counter i.e. address of the next instruction
CPU registers
. . . especially Stack Pointer
CPU scheduling information i.e. priority. . .

Memory-management information i.e. base/limit register, page tables


Accounting information i.e. CPU time used, time limits
I/O status information i.e. list of I/O device allocated, list of open files

Process Management I

Sohail (http://csrdu.org/sohail)

9 / 26

PROCESS CONTROL BLOCK (PCB) (COND.)

Process Management I

Sohail (http://csrdu.org/sohail)

10 / 26

PROCESS SCHEDULING


Multiprogramming have some process running at all times

Time Sharing Let users interact with each program while it is


running

Maximize CPU utilization

Minimize response time

To meet these objectives, the process scheduler selects an available


process for program execution on the CPU.

For a single-processor system, there will never be more than one


running process

The reset process will have to wait until the CPU is free and can be
rescheduled

Process Management I

Sohail (http://csrdu.org/sohail)

11 / 26

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

Process Management I

Sohail (http://csrdu.org/sohail)

12 / 26

READY QUEUE AND VARIOUS I/O DEVICE QUEUES

Process Management I

Sohail (http://csrdu.org/sohail)

13 / 26

REPRESENTATION

Process Management I

OF

PROCESS SCHEDULING

Sohail (http://csrdu.org/sohail)

14 / 26

SCHEDULERS


A processes migrates among the various scheduling queues


throughout its lifetime
The OS must select, for scheduling purposes, processes from these
queues in some fashion
The selection process is carried out by the appropriate scheduler

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

Process Management I

Sohail (http://csrdu.org/sohail)

15 / 26

SCHEDULERS


Short-term scheduler is invoked very frequently (milliseconds)


(must be fast)

Long-term scheduler is invoked very infrequently (seconds, minutes)

(may be slow)


The long-term scheduler controls the degree of multiprogramming


(the number of processes in memory)

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

Process Management I

Sohail (http://csrdu.org/sohail)

16 / 26

ADDITION

OF

MEDIUM TERM SCHEDULING

Process Management I

Sohail (http://csrdu.org/sohail)

17 / 26

CPU SWITCH FROM PROCESS

Process Management I

TO

PROCESS

Sohail (http://csrdu.org/sohail)

18 / 26

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
perform a state save of the current state of the CPU
and then a state restore to resume operations




Context of a process represented in the PCB


Context-switch time is overhead; the system does no useful work
while switching

Time dependent on hardware support

Process Management I

Sohail (http://csrdu.org/sohail)

19 / 26

OPERATIONS



ON

PROCESSES PROCESS CREATION

A process may create several new processes during its execution


Parent process create children processes, which, in turn create other
processes, forming a tree of processes

Generally, process identified and managed via a process identifier


(PID)

Resource sharing

Parent and children share all resources


Children share subset of parents resources

Parent and child share no resources

Execution
Parent and children execute concurrently
Parent waits until children terminate

Process Management I

Sohail (http://csrdu.org/sohail)

20 / 26

OPERATIONS


PROCESSES PROCESS CREATION

(COND.)

Address space

ON

Child duplicate of parent


Child has a program loaded into it

UNIX examples

fork system call creates new process


exec system call used after a fork to replace the process memory
space with a new program

Process Management I

Sohail (http://csrdu.org/sohail)

21 / 26

PROCESS CREATION SEQUENCE

Process Management I

Sohail (http://csrdu.org/sohail)

22 / 26

C PROGRAM FORKING SEPARATE PROCESS


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

int main() {
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}
Process Management I

Sohail (http://csrdu.org/sohail)

23 / 26

TREE OF PROCESSES ON A TYPICAL

Process Management I

SOLARIS

Sohail (http://csrdu.org/sohail)

24 / 26

OPERATIONS


PROCESSES PROCESS TERMINATION

Process executes last statement and asks the operating system to


delete it (exit)

ON

Output data from child to parent (via wait)


Process resources are deallocated by operating system

Parent may terminate execution of children processes (abort)


Child has exceeded allocated resources
Task assigned to child is no longer required
If parent is exiting

Some operating system do not allow child to continue if its parent


terminates

All children terminated - cascading termination

Process Management I

Sohail (http://csrdu.org/sohail)

25 / 26

End of Lecture 3

Process Management I

Sohail (http://csrdu.org/sohail)

26 / 26

S-ar putea să vă placă și