DOC PREVIEW
LSU CSC 4103 - Processes

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 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 19 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 19 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 19 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 19 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 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1CSC 4103 - Operating SystemsFall 2009Tevfik Ko!arLouisiana State UniversitySeptember 1st, 2009Lecture - IIIProcesses2Roadmap• Processes– Basic Concepts– Process Creation– Process Termination– Context Switching– Process Queues– Process Scheduling– Interprocess Communication3Process Concept• a Process is a program in execution;Typical process image implementationStallings, W. (2004) Operating Systems:Internals and Design Principles (5th Edition). !A process image consists of three components1. an executable program2. the associated data needed by the program3. the execution context of the process, which contains all information the O/S needs to manage the process (ID, state, CPU registers, stack, etc.)useraddressspaceProcess Control Block4!The Process Control Block (PCB)Typical process image implementation"is included in the context, along with the stack"is a “snapshot” that contains all necessary and sufficient data to restart a process where it left off (ID, state, CPU registers, etc.)"is one entry in the operating system’s process table (array or linked list)PCB 1 PCB 2 PCB 3. . .contextuser address spaceprogramcodedatastackprocess control block (PCB)Process Control Block5Illustrative contents of a process image in (virtual) memory!Example of process and PCB location in memoryO/Sprocess 2process 1contextprogramcodedataprogramcodedatastackprocess control block (PCB)identificationprogramcodedatastackCPU state infocontrol infostack• numeric identifier• parent identifier• user identifier• etc.• user-visible registers• control & status registers• program counter• stack pointers, etc.•• schedulg & state info• links to other proc’s• memory limits• open files• etc.6Process State• As a process executes, it changes state– new: The process is being created– ready: The process is waiting to be assigned to a processor– running: Instructions are being executed– waiting: The process is waiting for some event to occur– terminated: The process has finished executionProcess Creation7!Some events that lead to process creation (enter)!Some events that lead to process creation (enter)"the system boots#when a system is initialized, several background processes or “daemons” are started (email, logon, etc.)"a user requests to run an application#by typing a command in the CLI shell or double-clicking in the GUI shell, the user can launch a new process"an existing process spawns a child process#for example, a server process (print, file) may create a new process for each request it handles#the init daemon waits for user login and spawns a shell"a batch system takes on the next job in lineall cases of process spawningProcess Creation8!Process creation by spawningSilberschatz, A., Galvin, P. B. and Gagne. G. (2003)Operating Systems Concepts with Java (6th Edition). A tree of processes on a typical UNIX systemProcess Creation9...int main(...){ ... if ((pid = fork()) == 0) // create a process { fprintf(stdout, "Child pid: %i\n", getpid()); err = execvp(command, arguments); // execute child // process fprintf(stderr, "Child error: %i\n", errno); exit(err); } else if (pid > 0) // we are in the { // parent process fprintf(stdout, "Parent pid: %i\n", getpid()); pid2 = waitpid(pid, &status, 0); // wait for child ... // process } ... return 0;} Implementing a shell command interpreter by process spawningProcess Creation10O/SP1 contextP1 programP1 data1. Clone child process"pid = fork()process 1O/SP1 contextP1 programP1 dataP2 contextP2 programP2 data2. Replace child’s image" execve(name, ...)! P1 contextP1 programP1 dataO/SP1 contextP1 programP1 dataprocess 2Fork Example 1#include! <stdio.h>main(){! int!ret_from_fork, mypid;! mypid = getpid();! ! ! /* who am i? ! */! printf("Before: my pid is %d\n", mypid); /* tell pid */! ret_from_fork = fork();! sleep(1);! printf("After: my fork returns pid : %d, said %d\n",!!!ret_from_fork, getpid());}11Fork Example 2#include! <stdio.h>main(){! fork();! fork();! fork();! printf("my pid is %d\n", getpid() );}How many lines of output will this produce?12Process Termination13!Some events that lead to process termination (exit)!Some events that lead to process termination (exit)"regular completion, with or without error code#the process voluntarily executes an exit(err) system call to indicate to the O/S that it has finished"fatal error (uncatchable or uncaught)#service errors: no memory left for allocation, I/O error, etc.#total time limit exceeded#arithmetic error, out-of-bounds memory access, etc."killed by another process via the kernel#the process receives a SIGKILL signal#in some systems the parent takes down its children with itO/S-triggered(following systemcall or preemption)process-triggeredhardware interrupt-triggeredsoftware interrupt-triggeredProcess Pause/Dispatch14!Some events that lead to process pause / dispatch!Some events that lead to process pause / dispatch"I/O wait#a process invokes an I/O system call that blocks waiting for the I/O device: the O/S puts the process in “Waiting” mode and dispatches another process to the CPU"preemptive timeout#the process receives a timer interrupt and relinquishes control back to the O/S dispatcher: the O/S puts the process in “Ready” mode and dispatches another process to the CPU #not to be confused with “total time limit exceeded”, which leads to process terminationO/S-triggered(following system call)hardware interrupt-triggered (timer)15Process “Context” Switching• When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process• Context-switch time is overhead; the system does no useful work while switching• Switching time is dependent on hardware support16CPU Switch From Process to ProcessProcess “Context” Switching17!How does a full process switch happen, step by step?1. save CPU context, including PC and registers (the only step needed in a simple mode switch)2. update process state (to “Ready”, “Blocked”, etc.) and other related fields of the PCB3. move the PCB to the appropriate queue4. select another process for execution: this decision is made by the CPU scheduling algorithm of the O/S5. update the PCB of the selected process (state = “Running”)6. update memory management structures7. restore CPU


View Full Document

LSU CSC 4103 - Processes

Download Processes
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 Processes 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 Processes 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?