DOC PREVIEW
UB CSE 421 - Process Desc And Control

This preview shows page 1-2-14-15-30-31 out of 31 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Processes and ThreadsProcesses The Process ModelWhat is a process?Process creationTermination of a processProcess controlProcess control (contd.)UNIX Process CreationProcess creation - Examplefork and execExampleVersion of execProcess HierarchiesProcess StatesA five-state process modelState Transition Diagram (1)Process suspensionProcess suspension (contd.)State Transition Diagram (2)Implementation of Processes (1)Implementation of Processes (2)Operating System Control StructuresProcess descriptionProcess control blockProcess control block (contd.)Slide 26Slide 27Queues as linked lists of PCBsOS Functions related to ProcessesModes of executionSummaryPage 1Processes and ThreadsChapter 2Page 2ProcessesThe Process Model•Multiprogramming of four programs•Conceptual model of 4 independent, sequential processes•Only one program active at any instantPage 3What 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 4Process 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 5Termination 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 6Process 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 7Process 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 8UNIX 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 processPage 9Process creation - Examplemain () { 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 10fork 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 11Exampleif (( result = fork()) == 0 ) { // child code if (execv (“new program”,..) < 0) perror (“execv failed “); exit(1);} else if (result < 0 ) perror (“fork”); …}/* parent code */Page 12Version 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 13Process 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 equalPage 14Process States •Possible process states–running–blocked–ready•Transitions between states shownPage 15A 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 16State Transition Diagram (1) NEWREADYRUNN INGBLOCKEDEXITAdmitDispatchTime-outReleaseEvent WaitEvent OccursThink of the conditions under which state transitions may take place.Page 17Process 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


View Full Document

UB CSE 421 - Process Desc And Control

Documents in this Course
Security

Security

28 pages

Threads

Threads

24 pages

Security

Security

20 pages

Security

Security

52 pages

Security

Security

20 pages

Load more
Download Process Desc And Control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Process Desc And Control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Process Desc And Control 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?