Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Chapter 3 Process Description and Control
Introduction to Processes
6/9/2015B.Ramamurthy1 Process Description and Control B.Ramamurthy.
Process Description and Control
The Process Model.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Unix Processes.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process Description and Control
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process Description and Control
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 3 Process Description and Control
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Chapter 3 Process Description and Control
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Politecnico di Milano © 2001 William Fornaciari Operating System Processes Lecturer: William Fornaciari Politecnico di Milano
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
1 Process Description and Control Chapter 3. 2 Requirements of an Operating System Interleave the execution of multiple processes to maximize processor.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Process Description and control G.Anuradha (Referred from william stallings and galvin 8 th edition)
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Process concept.
Process Description and Control
System Structure and Process Model
System Structure and Process Model
System Structure B. Ramamurthy.
System Structure and Process Model
Process & its States Lecture 5.
Process Description and Control
Process Description and Control
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Process Description and Control
Process Description and Control
Process Description and Control in Unix
Process Description and Control in Unix
Presentation transcript:

Page 1 Processes and Threads Chapter 2

Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential processes Only one program active at any instant

Page 3 What is a process? A process is simply a program in execution: an instance of a program execution. Unit of work individually schedulable by an operating system. OS keeps track of all the active processes and allocates system resources to them according to policies devised to meet design performance objectives. To meet process requirements OS must maintain many data structures efficiently. The process abstraction is a fundamental OS means for management of concurrent program execution. Example: instances of process co-existing.

Page 4 Process creation Four common events that lead to a process creation are: 1) When a new batch-job is presented for execution. 2) When an interactive user logs in / system initialization. 3) When OS needs to perform an operation (usually IO) on behalf of a user process, concurrently with that process. 4) To exploit parallelism an user process can spawn a number of processes.

Page 5 Termination of a process Normal completion, time limit exceeded, memory unavailable Bounds violation, protection error, arithmetic error, invalid instruction IO failure, Operator intervention, parent termination, parent request, killed by another process A number of other conditions are possible. Segmentation fault : usually happens when you try write/read into/from a non-existent array/structure/object component. Or access a pointer to a dynamic data before creating it. (new etc.) Bus error: Related to function call and return. You have messed up the stack where the return address or parameters are stored.

Page 6 Process control Process creation in unix is by means of the system call fork(). OS in response to a fork() call: –Allocate slot in the process table for new process. –Assigns unique pid. –Makes a copy of the process image, except for the shared memory. –Move child process to Ready queue. –it returns pid of the child to the parent, and a zero value to the child.

Page 7 Process control (contd.) All the above are done in the kernel mode in the process context. When the kernel completes these it does one of the following as a part of the dispatcher: –Stay in the parent process. Control returns to the user mode at the point of the fork call of the parent. –Transfer control to the child process. The child process begins executing at the same point in the code as the parent, at the return from the fork call. –Transfer control another process leaving both parent and child in the Ready state.

Page 8 UNIX Process Creation Every process, except process 0, is created by the fork() system call –fork() allocates entry in process table and assigns a unique PID to the child process –child gets a copy of process image of parent: both child and parent are executing the same code following fork() –but fork() returns the PID of the child to the parent process and returns 0 to the child process

Page 9 Process creation - Example main () { int pid; cout << “ just one process so far”<<endl; pid = fork(); if (pid == 0) cout <<“I am the child “<< endl; else if (pid > 0) cout <<“I am the parent”<< endl; else cout << “fork failed”<< endl;}

Page 10 fork and exec Child process may choose to execute some other program than the parent by using exec call. Exec overlays a new program on the existing process. Child will not return to the old program unless exec fails. This is an important point to remember. Why does fork need to clone? Why do we need to separate fork and exec? Why can’t we have a single call that fork a new program?

Page 11 Example if (( result = fork()) == 0 ) { // child code if (execv (“new program”,..) < 0) perror (“execv failed “); exit(1); } else if (result < 0 ) perror (“fork”); …} /* parent code */

Page 12 Version of exec Many versions of exec are offered by C library: exece, execve, execvp,execl, execle, execlp We will look at these and methods to synchronize among various processes (wait, signal, exit etc.).

Page 13 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 14 Process States Possible process states –running –blocked –ready Transitions between states shown

Page 15 A five-state process model Five states: New, Ready, Running, Blocked, Exit New : A process has been created but has not yet been admitted to the pool of executable processes. Ready : Processes that are prepared to run if given an opportunity. That is, they are not waiting on anything except the CPU availability. Running: The process that is currently being executed. (Assume single processor for simplicity.) Blocked : A process that cannot execute until a specified event such as an IO completion occurs. Exit: A process that has been released by OS either after normal termination or after abnormal termination (error).

Page 16 State Transition Diagram (1) NEW READY RUNNING BLOCKED EXIT Admit Dispatch Time-out Release Event Wait Event Occurs Think of the conditions under which state transitions may take place.

Page 17 Process suspension Many OS are built around (Ready, Running, Blocked) states. But there is one more state that may aid in the operation of an OS - suspended state. When none of the processes occupying the main memory is in a Ready state, OS swaps one of the blocked processes out onto to the Suspend queue. When a Suspended process is ready to run it moves into “Ready, Suspend” queue. Thus we have two more state: Blocked_Suspend, Ready_Suspend.

Page 18 Process suspension (contd.) Blocked_suspend : The process is in the secondary memory and awaiting an event. Ready_suspend : The process is in the secondary memory but is available for execution as soon as it is loaded into the main memory. State transition diagram on the next slide. Observe on what condition does a state transition take place? What are the possible state transitions?

Page 19 State Transition Diagram (2) NEW READY RUNNING BLOCKED EXIT Admit Dispatch Time-out Release Event Wait Event Occurs Think of the conditions under which state transitions may take place. Activate Suspend Event occurs Activate Suspend Blocked Suspend Ready Suspend

Page 20 Implementation of Processes (1)

Page 21 Implementation of Processes (2) Skeleton of what lowest level of OS does when an interrupt occurs

Page 22 Operating System Control Structures An OS maintains the following tables for managing processes and resources: –Memory tables (see later) –I/O tables (see later) –File tables (see later) –Process tables (this chapter)

Page 23 Process description OS constructs and maintains tables of information about each entity that it is managing : memory tables, IO tables, file tables, process tables. Process control block: Associated with each process are a number of attributes used by OS for process control. This collection is known as PCB.

Page 24 Process control block Contains three categories of information: 1) Process identification 2) Process state information 3) Process control information Process identification: –numeric identifier for the process (pid) –identifier of the parent (ppid) –user identifier (uid) - id of the usr responsible for the process.

Page 25 Process control block (contd.) Process state information: –User visible registers –Control and status registers : PC, IR, PSW, interrupt related bits, execution mode. –Stack pointers

Page 26 Process control block (contd.) Process control information: –Scheduling and state information : Process state, priority, scheduling-related info., event awaited. –Data structuring : pointers to other processes (PCBs): belong to the same queue, parent of process, child of process or some other relationship. –Interprocess comm: Various flags, signals, messages may be maintained in PCBs.

Page 27 Process control block (contd.) Process control information (contd.) –Process privileges: access privileges to certain memory area, critical structures etc. –Memory management: pointer to the various memory management data structures. –Resource ownership : Pointer to resources such as opened files. Info may be used by scheduler. PCBs need to be protected from inadvertent destruction by any routine. So protection of PCBs is a critical issue in the design of an OS.

Page 28 Queues as linked lists of PCBs

Page 29 OS Functions related to Processes Process management: Process creation, termination, scheduling, dispatching, switching, synchronization, IPC support, management of PCBs Memory management: Allocation of address space to processes, swapping, page and segment management. IO management: Buffer management, allocation of IO channels and devices to processes. Support functions: Interrupt handling, accounting, monitoring.

Page 30 Modes of execution Two modes : user mode and a privileged mode called the kernel mode. Why? It is necessary to protect the OS and key OS tables such as PCBs from interference by user programs. In the kernel mode, the software has complete control of the processor and all its hardware. When a user makes a system call or when an interrupt transfers control to a system routine, an instruction to change mode is executed. This mode change will result in an error unless permitted by OS.

Page 31 Summary A process is a unit of work for the Operating System. Implementation of the process model deals with process description structures and process control methods. Process management is the of the operating system requiring a range of functionality from interrupt handling to IO management. Next we will look at “unix process” as a case study. This will be illustrated in the project 1.