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 Process definition A process is a program in execution
Process needs resources : CPU time memory to files accomplish I/O device its tasks These resources are allocated to process when it is created or during execution Process is the unit of work of system System consists of collection of processes

3 Process OS processes execute system code, user code
Processes can be executed concurrently (parallel) or sequential Program can be single thread or Multithreading Thread is a sequence of instructions that can be managed independently Thread is the component of process Multithreading more than one thread in the same process share resources and memory

4 Multithreading process

5 Process concept What to call the CPU activities ? (CPU Cycle)
All kind of CPU activities are called process Batch system time shared single user OS system Execute jobs execute task run several programs Is an operating system that work without the interaction of user Are process

6 Process Process is more than program code, it includes:
Current activity represented by the value of program counter Content of processor registers Stack which contains temporary data (function, parameters, return address, local variable) in which is inserted data used during instruction execution Data section : which include global variables Heap that is memory dynamically allocated during process runtime

7 click program Loaded into memory Passive CPU In execution process Active But Not yet process PC In which instruction Data section heap Memory Content of registers Stack

8 are variables declared at the beginning of the program and
Global variables : are variables declared at the beginning of the program and can be used in any part of the program Local variables : are variables declared inside part of the program and can be used only inside this part of the program When the user click two times on a program It creates two separate processes With two stacks and two heaps …..

9 Process state The state is part of the current activity of the process
The process can have the following states: New : created Running instructions are being executed Waiting the process waits some event like I/O Ready the process is waiting to be assigned a processor Terminated the process finished execution In each instant only one process can be running on a processor

10 Diagram of Process State

11 Process control block PCB
Each process in operating system is represented by PCB that contains information about the process . It contains the following information : process state : new , running, waiting, ready , terminating PC Program counter that indicates the address of next instruction to be executed (this information must be saved when an interrupt is happened) CPU registers : type , index of registers, stack , pointers

12 Process control block PCB continue
CPU scheduling : information , priorities Memory management information : limit registers, page table segment, table depend on memory used by OS Accounting information : amount of CPU, real time used, tile limits, account number, job or process number I/O status information : list of I/O devices allocated to the process , list of open file….

13 Click New program 1 Running 3 passive CPU 3 registers 7 2 PC 6 I/O 4 Ready Scheduling Interrupt Segment Page 5 Memory

14 Threads A process is a program that perform single thread
Ex: word cannot type and control errors at the same time New OS can support more than one thread at time

15

16 Process scheduling The objective of multiprogramming is to have some process running at all times to maximize the CPU utilization Time sharing is to switch the CPU among processes so, the user can interact with program while in execution needs process scheduling Selects the available process for program execution on the CPU

17 Process scheduling One process no need for scheduling
More than one process ……..scheduling

18 Ready Queue And Various I/O Device Queues

19 Scheduling queue Process enter The system Memory system P P C C B B
Ready queue Job queue Waiting or Ready processes Linked list

20 Scheduling queue Header contains pointer to the first and last PCB (Program Control Block) that contains information about process Each PCB contains a pointer to the next process to be executed in this queue ready waiting for I/O device queue each device has its own queue keyboard Mouse CPU

21 Scheduler OS must select which process enter each queue, this selection is done by scheduler Many processes enter the system ….. All are sent to the queue …. Spooling Scheduler choose ………. Long term scheduler ………..short term scheduler

22 Long term scheduler Choose one process from spooler and load it into memory Execute 1 process each 100 milliseconds + it takes 10 millisecond for deciding which process is assigned …… during this time the memory is idle ….that means time is wasted One minute between create each process , it select I/O bound process Is a process that spends more CPU bound process Time in I/O operation than more computation A CPU operation time

23 If all processes are CPU bound waiting queue will be empty
I/O bound CPU bound Mixed If all processes I/O bound Ready queue Will be Empty If all processes are CPU bound waiting queue will be empty Unix and Windows has no long term scheduler

24 Swapping Swapping means move some process from short term memory to midterm memory All that is done by scheduling algorithms

25 Context switch When an interrupt is happened the state of the process is saved …….PCB Process ……………state saved To resume activity ……. State restore Context switch when the kernel switch between state saved to state restore It adds overhead on the system because the system does nothing useful

26 Operation on processes
The processes in most systems can be executed in parallel can be created and deleted dynamically Process creation : a process is created using create process system call A process can create many other processes . The first is called Parent and the subsequent processes are called children forming a tree of processes a process is identified using unique process identifier Pid that is an integer number

27 Process creation Consider a process needs resources, when a process is created the resources are allocated to it by its parent. If no available resources it can obtain a subset of the parent’s resources. The parent can distribute resources between its children without overloading the system Resources allocated to a child process must be passed by away of the parent

28 Process creation (continue)
When a process creates a sub process, there are two possibilities : Execution memory addresses Parent and the parent parent and the child Child are wait until its child use the uses new Executed child end execution same memory memory Concurrently space space

29 Process creation in Unix
Creating new process is done by Fork () call system The new process consists on copying the address space of the original process The two processes continue execution after fork system call with one difference that the returned value of fork () function is 0 for child process and is not zero for parent process parent and child can communicate to each other and the parent can create more child and uses the wait () system call and manage memory address space The child process inherits privileges from its parent

30 Process Creation

31 C Program Forking Separate Process
#include <sys/types.h> #include <studio.h> #include <unistd.h> int main() { pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); return 1; } else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); else { /* parent process */ /* parent will wait for the child */ wait (NULL); printf ("Child Complete"); return 0;

32 A Tree of Processes on Solaris

33 Windows creating process
Creating process in windows is done using Win 32 API using create process () system call that means loading the program into memory and load mspaint.exe application for execution.

34 Process terminate Process terminate when it finishes executing its final statement and asks the OS to delete it by using exit () system call The parent process resume activity using wait () system call All resources (physical and virtual memory, open files, I/O buffer ) are de-allocated by OS A process is terminate when it ends execution or by other process (parent)

35 Process terminate A parent terminate child process if :
Child process has exceeds the use of some resources The task assigned to child is no longer needed If the parent is exiting the OS does not permit to child to continue execution.

36 Inter-process communication
Processes executing concurrently in OS can be either independent or cooperating processes A process is independent if cannot affect or be affected by the other processes executed in the system Any process that does not share data with other processes is independent Cooperating process may share data with other processes (child)

37 Why cooperating ? Information sharing
Computation speedup, if we want a task to run faster, we divide it into subtasks and are executed in parallel . Speedup is allowed when more than one processor works together Modularity : dividing the system into modules or functions or threads Convenience : allows multi operations in parallel

38 Communication between processes
Cooperating process must communicate to each other . Types of communication Inter-process remote call indirect Communication

39 Inter-process communication
Memory shared message passing Part of memory is used communicating Between the two processes processes Both processes can read exchange data and And write to this region information by away of kernel

40 Shared Memory Allows maximum Speedup and Convenience
For communication No need for kernel Intervention Is faster than Message passing

41 Message passing Useful for By away Exchanging small Of kernel
Amount of data By away Of kernel Easy to Implement No conflict

42 How to share Establishing the region to be shared between the communicating processes from the memory address space assigned Creating one process ……address space Another process ….new address space Generally OS prevent that one process accesses the resources of another process…..the two processes must cooperate to remove the restrictions Both processes can read and write on the region without the OS control but not simultanously Part shared

43 Example of Cooperating processes
Producer Consumer Consume information Produce information Unlimited buffer buffer Shared memory Limited Buffer size

44 Explanation of producer- consumer example
Producer produces data stored in the buffer, the buffer is emptied by the consumer To allow this paradigm to work correctly, consumer and producer must be synchronized To To access shared data Consumer must Consume only The data produced by The producer The buffer is implemented using circular array with two pointers in and out In point to the next position in the buffer Out points to the first position in the buffer In==out mean buffer empty (in+1)%buffer size == out means buffer full

45 Message passing system
Processes communicate and synchronized without sharing memory Distributed systems over network Chat send (message) receive (message)

46 Indirect communication
Message passing communication Direct communication Indirect communication synchronization Synchronous asynchronous buffering Automatic Explicit buffer Each process want to send Message must explicit The name of the sender Send (P, message) By a way of third part server

47 Link property in direct communication
Link automatically Established between Two processes (after knowing process identity Exist only One link Link associated between two processes Full duplex

48 Naming mechanism for direct communication
Symmetric Only by message name Send( process name , message ) Receive (process name , message) (router) Asymmetric By ID Send (process name, message) Receive ( id, message) Is less desirable , it requires More work (switch)

49 Link property for indirect communication
Link is established Between two processes if They share Some resources Example : mail box Between the communicating Processes May be Different links router Link may be used by More than one process

50 Example P1 send message to A “ send (A, message)”, A want to respond to P1, P2,P3 that share the same mailbox which will receive the message b? The answer is depend on the link property : Each link can only one process Be shared can execute receive who receive Between only operation at time operation Two processes must be selected (round robin)

51 Synchronization Communication between two processes is done by send or receive operations
After send Block non block Block sending The process blocks Sending message send Until the previous Message arrive At destination After receive block non block The process block Receiving until Ending processing

52 Synchronization Send(block) ……… Receive (block) ……
Sender : send message + block …….wait Receiver : receive message +block ……….end block rendezvous Resume activity

53 No waiting in the buffer Packet arrived will be sent
Buffering Zero capacity No waiting in the buffer Packet arrived will be sent Sender :send + block Bounded capacity Length n When becoming full Blocking receive Unbounded capacity Never blocking Send or receive


Download ppt "Chapter 3 Process Management."

Similar presentations


Ads by Google