























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























(Based on slides by Geoffrey Voelker)
Today’s Topics Processes
What does the OS have to manage? Programs: Processes, Threads, Synchronization I/O: Hardware, Interrupts, Direct Memory Access Memory/Disk: Virtual Memory, Paging, Naming The first half of the class will cover this piece
What is a process? A process is a program in execution Sometimes called a job or a task What does it mean for a program to be “in execution”? How can more than one program be “in execution” at the same time? What’s the difference between a process and a program? Why do we need processes?
What does a program need to execute? An address space Program counter pointing to next instruction Registers containing current values Code for executing the program Data used by the program Execution stack containing the procedure calls OS resources (open files, network connections, etc…) The process keeps track of all of these things
Process State I thought you said a process was a program in execution… how can it have different states? Remember, the CPU is only part of the story… States: New : Process is being created. Running : Process is using the CPU Waiting : Process is waiting on some event (What’s an event?) Ready : Process is ready to get back to the CPU Terminated : Process has finished execution For each state, how many processes can be in that state? What state takes up the most time?
Moving from State to State New Terminated Running Ready Waiting Process admitted interrupt dispatch I/O event Need I/O exit
Let’s be processes… One volunteer to be the CPU: Determines when processes finish, fork, or need I/O One volunteer to be the I/O: Hands out I/O I will be the scheduler and call interrupts Everyone else is a process…
The Process Control Block (PCB) Keeps track of all the information needed by the process Usually a process is not running, so it keeps track of everything the process needs to run too (PC, registers, Stack Pointer): This is everything the process needs to pick up right where it left off
PCB is a huge data structure Contains: Process ID (PID) Execution state Hardware state: PC, SP, regs Memory Management List of open files Accounting (e.g., how much CPU time has this process had?) Etc. Unix: PCB is defined in sys/proc.h as struct proc FreeBSD: 81 fields, 408 bytes!
State Queues How does the OS keep track of processes? There are a collection of queues to keep track of where all processes are. Give an example of these queues from our exercise. One queue for each state Each PCB is on a queue according to its current state. PCBs move from queue to queue.
State Queues Illustrated Ready queue Mozilla^ PCB^ AOL IM PCB Disk I/O queue Emacs^ PCB^ ls^ PCB Console queue Sleep queue … Usually one queue for each type of wait Why would these processes be on this queue?
Process Creation A process is created by another process Creator=parent; Created=child Where does child get its resources (CPU time, disk I/O, etc)? From parent From OS What are the advantages/disadvantages of each? After creating a child, what happens to the parent? Waits Continues to run
Process Creation: NT The system call on NT for creating a process is (simplified): BOOL CreateProcess(char* prog, char* args) CreateProcess: Creates and initializes a new PCB Creates and initializes a new address space Loads the program pointed to by prog into the address space Copies args into the memory allocated in address space Initializes hardware context to start execution at “main” Places the PCB onto the ready queue