Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems Processes 1.

Similar presentations


Presentation on theme: "Operating Systems Processes 1."— Presentation transcript:

1 Operating Systems Processes 1

2 Objectives What’s process?
What’s the difference between program and process? What about process’s lifecycle?

3 The Process Model (a) Multiprogramming of four programs. (b) Conceptual model of four independent, sequential processes. (c) Only one program is active at once.

4 Process A process consists of three parts: 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

5 Processes Control Block
Some of the fields of a typical process table entry.

6 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

7 Process Creation 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.

8 fork main() { 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); }

9 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. bash fork() exec() ls -l exit()

10 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); }

11 The life of a process

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

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

14 Process Termination Events which cause process termination:
Normal exit (voluntary). Error exit (voluntary). Fatal error (involuntary). Killed by another process (involuntary).

15 Implementation of Processes (3)
Skeleton of what the lowest level of the operating system does when an interrupt occurs.

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

17 Summary Pseudo-parallelism vs. multiprocessor Program vs. process
Process Hierarchies Process lifecycle Process states System Calls: fork() vfork() execl() execv() execle() execve() execlp() execvp() wait() waitpid() exit() system()


Download ppt "Operating Systems Processes 1."

Similar presentations


Ads by Google