1 / 15

Chapter 2.1 : Processes

Chapter 2.1 : Processes. Process concept Process scheduling Interprocess communication Threads. What is a Process?. A process (task) is the activity resulting from the execution of a program with its data on a sequential processor A process is an abstract form of a program. Start.

ferrol
Download Presentation

Chapter 2.1 : Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2.1 : Processes • Process concept • Process scheduling • Interprocess communication • Threads

  2. What is a Process? • A process (task) is the activity resulting from the execution of a program with its data on a sequential processor • A process is an abstract form of a program

  3. Start Program 1 Program 2 Program 3 Terminate Sequential Execution • Programs are run one after the other (run to completion)

  4. Start Start Start Program 1 Program 2 Program 3 Terminate Terminate Terminate Concurrent Execution • All programs execute concurrently (share the time of the CPU)

  5. Start Start Start Code 1 Code 3 Code 2 Data 3 Data 1 Data 2 PCB 2 PCB 3 PCB 1 Terminate Terminate Terminate How to Implement Concurrency? • Separate a program into code, data and environment (Process table) segments • Process table contains all the necessary data to stop and restart a process at any time

  6. Process Table (PCB - Process Control Block) • Contents of registers • Program counter • PSW (Program Status Word) • Process state • Pointers to code and data • Process identifier (PID) • Process priority • File descriptors • Pointer to the parent of the process • Pointers to all children of the process • The processor it is running on

  7. Switching Processes • Save the “real world” of the currently active process in process table • Restore the “real world” from the process table of the selected process (the one to be executed next)

  8. System Process Tables Process Tables Code Process Data Stack

  9. PCB 2 PCB 1 Shared Code Data 1 Data 2 Shared Code • The shared code must be re-entrant (ie., it must not modify itself)

  10. Running Running Running Running Process States PREEMPT Create Ready SCHEDULE CONTINUE Blocked SUSPEND Terminate

  11. Process States • Create • A process is created by an existing process (parent/child); a process is created by a service, or as a new batch job, or an interactive logon • Terminate • Normal completion (exit); External completion (forced completion: by operator, by parent); Internal completion (error, time overrun) • Schedule • A process is selected out of the ready queue (is scheduled) and dispatched to the running state • Preempt • The running process is preempted because some other process of higher priority has become ready (or it yields)

  12. Process States • Suspend • A process starts a time consuming IO operation, or is swapped out, or makes a spontaneous request to sleep, or is blocked in a synchronization operation. When a process is suspended, it is on some queue, namely the queue of all the processes waiting for the same resource. Processes during their life move from queue to queue, with stays in the running state • Continue • The inverse of Suspension: the resource requested becomes available (timer, IO completes, unblocking)

  13. How to Create New Processes? Fork & Exec • fork • create a new process that is a copy of current one • exec • change the program that a process is executing • Some systems combine the two into one

  14. A Simple Shell void main() { int child; if ( (child = fork())==-1 ) return( -1 ); else if ( child==0 ) { printf( "This is the child executing\n"); exit(1); } printf( "This is the parent\n" ); }

  15. root p3 p1 p2 p4 p5 Parent Child Relationship • root is the parent • p1, p2 and p3 are children of root process • p4 and p5 are children of p3

More Related