Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3: Process Management

Similar presentations


Presentation on theme: "Chapter 3: Process Management"— Presentation transcript:

1 Chapter 3: Process Management

2 Important Terminologies
Task When a program is requested for execution it is called a task. Before pressing enter key. Job When the OS checks the validity of the task by searching it in internal page table, if present then it is said to be a valid job for further processing. Process The job is then loaded into computer memory, after memory allocation, the program is set into execution.

3 Example When we write on the console, C:\>dir
A task has been given to OS OS checks its validity by searching it into internal page table, if found, then it is valid, become a job When it become a job, OS must load it into memory. Now this program under execution along with its environment is called a Process.

4 Process Management A process is a program in execution. It is a unit of work within the system. Program is a passive entity, process is an active entity. Process needs resources to accomplish its task CPU, memory, I/O, files Initialization data Process termination requires reclaim of any reusable resources Single-threaded process has one program counter specifying location of next instruction to execute Process executes instructions sequentially, one at a time, until completion Multi-threaded process has one program counter per thread Typically system has many processes, some user, some operating system running concurrently on one or more CPUs Concurrency by multiplexing the CPUs among the processes / threads

5 Process Management Activities
The operating system is responsible for the following activities in connection with process management: Creating and deleting both user and system processes Suspending and resuming processes Providing mechanisms for process synchronization Providing mechanisms for process communication Providing mechanisms for deadlock handling

6 Process State As a process executes, it changes state
Ready: The process is waiting to be assigned to a processor Running: Instructions are being executed

7 Interrupts Resume Answer the Phone
The occurrence of an event is usually signaled by an interrupt from either the hardware or the software. Hardware may trigger an interrupt at any time by sending a signal to the CPU usually by way of the system bus. Software may trigger an interrupt by executing a special operation called a system call. Answer the Phone . Resume

8 Example Process Burst Time Start/Arrival Time P1 40 sec 0 sec P2
CPU time slice = 10 sec

9 P1 & P2 States Time Instant P1 P2 Running Ready 10 20 30 40 50 60 70 -

10 Class Exercise

11 Example Process Burst Time Start/Arrival Time P1 30 sec 0 sec P2
CPU time slice = 10 sec

12 P1 & P2 States Time Instant P1 P2 Running Ready 10 20 30 40 50 - 60 70

13 Operations on Processes
System must provide mechanisms for process creation, termination, and so on as detailed next

14 Process Creation 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 options Parent and children share all resources Children share subset of parent’s resources Parent and child share no resources Execution options Parent and children execute concurrently Parent waits until children terminate

15 A Tree of Processes in Linux

16 Process Termination Process executes last statement and asks the operating system to delete it (exit()) Output data from child to parent (via wait()) Process’ resources are de-allocated 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 systems do not allow child to continue if its parent terminates All children terminated - cascading termination

17 Process State Modified
As a process executes, it changes state New: The process is being created Running: Instructions are being executed Ready: The process is waiting to be assigned to a processor Terminated: The process has finished execution

18 Process State Modified
As a process executes, it changes state New: The process is being created Running: Instructions are being executed Waiting: The process is waiting for some event to occur Ready: The process is waiting to be assigned to a processor Terminated: The process has finished execution

19 Diagram of Process State

20 Example Process Burst Time Start/Arrival Time P1 40 sec 0 sec P2
CPU time slice = 10 sec P1 does an I/O for 10 sec at 20 P2 does an I/O for 20 sec at 40

21 P1 & P2 States Time Instant P1 P2 Running Ready 10 20 Blocked for I/O
Running Ready 10 20 Blocked for I/O 30 40 50 60 Exit 70 -

22 Class Exercise

23 Example Process Burst Time Start/Arrival Time P1 40 sec 0 sec P2
CPU time slice = 10 sec P1 does an I/O for (10 x 2) sec at 20 and 50 P2 does an I/O for (10 x 2) sec at 40 and 60

24 P1 & P2 States Time Instant P1 P2 Running Ready 10 20 Blocked for I/O
Running Ready 10 20 Blocked for I/O 30 40 50 60 70 Exit

25 To make sure… You have Understood !
Process Burst Time Start/Arrival Time P1 30 sec 0 sec P2 40 sec CPU time slice = 10 sec P1 does an I/O for 10 sec at 20 P2 does an I/O for 30 sec at 30

26 P1 & P2 States Time Instant P1 P2 Running Ready 10 20 Blocked for I/O
Running Ready 10 20 Blocked for I/O 30 40 50 Exit 60 - 70

27 Process Control Block (PCB)
Information associated with each process (also called task control block) Process state – running, waiting, etc. Program counter – location of instruction to next execute CPU registers – contents of all process-centric registers CPU scheduling information – priorities, scheduling queue pointers Memory-management information – memory allocated to the process Accounting information – CPU used, clock time elapsed since start, time limits I/O status information – I/O devices allocated to process, list of open files

28 Threads So far, process has a single thread of execution
Consider having multiple program counters per process Multiple locations can execute at once Multiple threads of control -> threads Must then have storage for thread details, multiple program counters in PCB.

29 Single and Multithreaded Processes

30 Threads Example: Consider a multi-threaded application. If one thread is blocked by some I/O request, the other can continue its execution. Switching among threads is faster. Only PC and registers Threads are also known as ‘lightweight’ process. Only one thread can be executed at a time A thread can be in one of the several states, like Rn, Rd etc. Different stacks and registers But same memory

31 Synchronization Multithreaded applications Multiprocessor systems
Concurrent processing Various problems are associated with it Critical section

32 Critical section Critical Section Starts
Cout<<“Result before increment”<<i; i++; Cout<<“Result after increment”<<i; Cout<<“Result before multiplication”<<i; i=i*3; Cout<<“Result after multiplication”<<i; Critical Section Ends

33 Mutual Exclusion While (entry == True) entry = False
Cout<<“Result before increment”<<i; i++; Cout<<“Result after increment”<<i; Cout<<“Result before multiplication”<<i; i=i*3; Cout<<“Result after multiplication”<<i; entry = True

34 Semaphores A semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access, by multiple processes, to a common resource in a parallel programming or a multi user environment. A library has 10 study rooms, to be used by one student at a time. Students must request a room from the front counter. When a student has finished using a room, (s)he must return to the counter. The clerk does not keep track of which room is occupied or who is using it. When a student requests a room, the clerk decreases this number. When a student releases a room, the clerk increases this number.

35 Semaphores The front desk represents a semaphore,
the rooms are the resources the students represent processes. The value of the semaphore in this scenario is initially 10. When a student requests a room he or she is granted access and the value of the semaphore is changed to 9. After the next student comes, it drops to 8, then 7 and so on.  A semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access, by multiple processes, to a common resource in a parallel programming or a multi user environment.


Download ppt "Chapter 3: Process Management"

Similar presentations


Ads by Google