operating systems processes. objectives 1.what’s process? 2.what’s the difference between...

17
Operating Systems Processes

Upload: cleopatra-morris

Post on 05-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Operating Systems

Processes

Page 2: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Objectives

1. What’s process?

2. What’s the difference between program and process?

3. What about process’s lifecycle?

Page 3: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

(a) Multiprogramming of four programs. (b) Conceptual model of four independent, sequential

processes.(c) Only one program is active at once.

The Process Model

Page 4: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Process• What’s process?

– A process is an instance of a computer program that is being executed. It contains the program code and its current activity.

• What is the difference between program and process?– Program is just the static text .– Process is an dynamic entity being executed and has

lifecycle.

• A process consists of three parts:– Process Control Block ( Process Table Entry)– Program (Text)– Data

Page 5: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Some of the fields of a typical process table entry.

Processes Control Block

Page 6: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

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 7: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Events which cause process creation:

• System initialization.• Execution of a process creation system call by a

running process.• A user request to create a new process.• Initiation of a batch job.

Process Creation

Page 8: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

forkmain(){

pid_t val;printf("PID before fork(): %d \n",(int)getpid());val=fork();if ( val > 0) {

printf("Parent PID: %d\n",(int)getpid());} else if (val == 0) {

printf("Child PID: %d\n",(int)getpid());} else {

printf(“Fork failed!”); exit(1);}

}

Page 9: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

bash fork()

exec() ls -l exit()

Shell and its children

• All processes are started by other processes– Parent/Child relationship

$ ls –l

• A process can be terminated for two reasons:– The process terminates itself when done.– The process is terminated by a signal from another process.

Page 10: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Code

pid_t val;int exit_code = 0;

val=fork();if (val > 0) {

int stat_val;pid_t child_pid;child_pid = waitpid(val,&stat_val,0);printf("Child has finished: PID = %d\n", child_pid);if(WIFEXITED(stat_val))

printf("Child exited with code %d\n", WEXITSTATUS(stat_val));else

printf("Child terminated abnormally\n");exit(exit_code);

} else if (val == 0) {execlp("ls","ls","-l",NULL);

}

Page 11: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

The life of a process

Page 12: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

A process can be in running, blocked, or ready state. Transitions between these states are as shown.

Process States

Page 13: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer are

sequential processes.

Scheduling

Page 14: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Events which cause process termination:

• Normal exit (voluntary).• Error exit (voluntary).• Fatal error (involuntary).• Killed by another process (involuntary).

Process Termination

Page 15: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Skeleton of what the lowest level of the operating system does when an interrupt occurs.

Implementation of Processes (3)

Page 16: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

CPU utilization as a function of the number of processes in memory.

Modeling Multiprogramming

Page 17: Operating Systems Processes. Objectives 1.What’s process? 2.What’s the difference between program and process? 3.What about process’s lifecycle?

Summary

1. Pseudo-parallelism vs. multiprocessor

2. Program vs. process

3. Process Hierarchies

4. Process lifecycle

5. Process states

6. System Calls:• fork() vfork()

• execl() execv() execle() execve() execlp() execvp()

• wait() waitpid()

• exit()

• system()