operating system concepts and techniques lecture 3

18
Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com , or www.amazon.com

Upload: ina

Post on 19-Jan-2016

21 views

Category:

Documents


1 download

DESCRIPTION

Operating System Concepts and Techniques Lecture 3. Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com , or www.amazon.com. Process. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Operating System Concepts and Techniques  Lecture 3

Operating System Concepts and

Techniques Lecture 3

Process

M. Naghibzadeh

ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011.

To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com

Page 2: Operating System Concepts and Techniques  Lecture 3

2

ProcessProcess: born to run programs

Inside a computer there is a little society of processes; Processes are

born, live, and dieOperating system is the governing

body of processesIt must keep information about

processes, called process attributes, to be able to manage them

Page 3: Operating System Concepts and Techniques  Lecture 3

Some attributes

3

Process identification information

Process ID

Parent process

User identifier

Group identifier

Process state information

Process-visible registers

Location counter

Condition code flags

Stack pointers

Process control information

Status

Priority

Process start time

CPU time used

Children’s CPU time used

Scheduling parameters

Links

Process privileges

Memory pointers

Devices assigned to the process

Open files

Flags

Page 4: Operating System Concepts and Techniques  Lecture 3

Process Control Block (PCB)

Process attributes are kept in an operating system structure called PCB;

One for each processThere is one process table in the

system Each row is for one process; it either has all PBC information of the process or some of it and a pointer to the PCB; the latter is

our conventionWhen process is terminated its PCB is

removed

4

Page 5: Operating System Concepts and Techniques  Lecture 3

Process table

5

Properties of P1blocked

Properties of P2ready

Properties of P3blocked

Properties of P4running

Properties of P5ready

Properties of P6ready

Properties of P7blocked

Properties of P8ready

Properties of P9ready

Properties of P10blocked

Process properties State Link Link to PCB

Front of ready queue

Rear of ready queue

Page 6: Operating System Concepts and Techniques  Lecture 3

System callsKernel is robust, fault-free, and efficientIt includes numerous useful procedures

Some we can call from application programs, these are called system

calls, supervisor calls, or kernel services

Kernel is protected from outside world, entering and leaving is via an strict

controlled mechanism.

6

Page 7: Operating System Concepts and Techniques  Lecture 3

Breaking into kernel

7

…call a kernel service from an application program….

Other layers of

the operatin

g system

A kernel service

Kernel Barrier

Kernel

A B

Kernel barrier is busted twice as shown at points A and B

Although a kernel routine is used by an application program, it is like taking a prisoner to an outside hospital for medical services while handcuffed and accompanied by two guards

Page 8: Operating System Concepts and Techniques  Lecture 3

Some system calls

8

Process Management

pid = fork()

pid = waitpid (pid, &static, options)

s = execve (name, argv, envp)

exit (status)

s = kill (pid, sig)

pause ()

wait (&status)

alarm (sec)

Interprocess Communication

qid = msgget(queueid, rights)

msgsnd(qid, &mymsg, size, flags)

msgrcv(qid, &mymsg, size, type, flags)

semid = semget(key, nsems, rights)

semop( semid, operation)

File System

fd = create (name, mode)

fd = open (file, how)

s = close (fd)

n = read (fd, buffer, nbytes)

n = write (fp, buffer, nbytes)

pos = lseek (fd, offset, whence)

s = stat (name, &buf)

s = mkdir (path, mode)

s = rmdir (path)

s = unlink (name)

s = chdir (name)

s = chmode (name, mode)

Page 9: Operating System Concepts and Techniques  Lecture 3

Unix Process State Transition Model

9

UNIX StatesThe corresponding state in the 3-stae model

Ready to Run Swapped

Ready to Run in Memory

Preempted

Sleep SwappedAsleep

In Memory

User Running

Created

Zombie

Kernel Running

Ready

Wait/

Blocked

Running

Process birth

Interrupt, Interrupt return

A process is picked to

run

Memory needed, swap out

Running obstacle is vanished

Preempt

System call or interrupt

Return

Not enough main memory

Main memory assigned

Sleep condition

ended

Exit, but not disappeared

Imaginary line

Back to running

Needs I/O or circumstance

Memory shortage swap out

Swap in

Page 10: Operating System Concepts and Techniques  Lecture 3

Why are Processes Created?

Processes are the means of running programs to perform tasks

Processes are created from executable files

10

Page 11: Operating System Concepts and Techniques  Lecture 3

When is a Process Created?

At computer start or restart, by OSExplicit request by a computer user

double clicking on an executable file opening an executable program file

issuing a command to run a program, etc.

In response to a request from a running process to create a child

process

11

Page 12: Operating System Concepts and Techniques  Lecture 3

Process creation/termination

Why are processes created?When is a process created?

What is done to create a process?What are the tools for creating a

process?What are common in parent and child

processes?What are different between parent and

child processes?How is a process terminated?

12

Page 13: Operating System Concepts and Techniques  Lecture 3

What is done to create a process?

Ensure the degree of multiprogramming does not been exceeds its maximum

Generate a unique process IDUse one row of Process table

Allocate space for the PCB and initialize proper fields; then make the connection between the corresponding

row of the process table and this PCBAllocate space for process context

Allocate space for other preliminary structures such as stacks and stack pointers and initialize the related fields

in PCBPut the process in one of the queues, usually ready

queue

13

Page 14: Operating System Concepts and Techniques  Lecture 3

Process creation using fork()

void main(void){

int pid; int retval;

int status; // Pointer to the value returned by the child process pid = fork(); // It is assume that, there is no obstacle in creating

// the child process if (pid != 0) // This is the parent process

{ proc1; // Parent process will continue running procedure proc1

wait (&status); // Wait until the child process is terminated } else {

proc2; // Child process will continue running procedure proc2 status = …; // Provide a valid value for the returned status to parent process

exit (status); }

}

14

Page 15: Operating System Concepts and Techniques  Lecture 3

How is a Process Terminated?

When its execution is completed it is logically terminated

For the physical termination of a process, all memory occupied as process images and stacks are first

freed. Then, the process control block is freed and the process is removed from the process table

Logical termination of a process takes less processing time than its physical termination. For logical

termination it suffices to change the terminating process’s state to terminated and to actually add this

process to the set of terminated processes.

It could be killed by OS or user

15

Page 16: Operating System Concepts and Techniques  Lecture 3

SummaryProcesses are one of the central issues of every operating

systemProcesses are created to run programs

Process state transition diagram shows the living states of process and its transactions

The request to create a process could come from a user, an application process, or the operating system itself

The same requesters could order the destruction of a process or it could be terminated automatically when its duty is

finished or when a fatal fault has occurred A process that requests the creation of another process

becomes the parent process and the created process is called the child process

A child process goes its own way right after it is createdAs UNIX is a process-based operating system, this chapter was

able to use actual examples from this operating system.

16

Page 17: Operating System Concepts and Techniques  Lecture 3

17

Find outThe purpose of system calls

The purpose of the transitions from kernel to itself

Complete set of Unix system callsThe deficiencies of process

How we can create a child process to run a different program (not a different

procedure)Whether Linux is a process-based

operating system or a thread-based one

Page 18: Operating System Concepts and Techniques  Lecture 3

18

Any questions?