80 likes | 189 Views
Chapter 4 Process Abstraction. Chien -Chung Shen CIS, UD cshen@cis.udel.edu. Process. P rocess is a running program A program itself is a lifeless thing sitting on disk with instructions (and static data) OS transforms a program into a running process Need to run many processes at once
E N D
Chapter 4Process Abstraction Chien-Chung Shen CIS, UD cshen@cis.udel.edu
Process • Process is a running program • A program itself is a lifeless thing sitting on disk with instructions (and static data) • OS transforms a program into a running process • Need to run many processes at once • Problem: how to provide the illusion of many CPUs? • virtualize the CPU – run one process, stop it, and then run another process, etc. • time sharing • scheduling policy & context switching mechanism
Machine State of Process • Address space (including stack) http://www.cs.umd.edu/class/spring2003/cmsc311/Notes/Mips/stack.html • CPU registers (including PC, SP, FP) • Opened files
Process API • Create – a process is created when an application icon is double-clicked • Destroy • Wait • Miscellaneous control – stop& resume • Status
Process Creation • Load code and static data into memory (address space) • Initialize (run-time) stack with argc & argv • Initialize 3 default file descriptors (0, 1, and 2) • Jump to main()
Process State (Life Cycle) • Running – using CPU • Ready – someone else is using CPU • Blocked – not ready until some other event takes place (e.g., initiate I/O request to disk)
Data Structures of OS • OS is a program itself containing data structures • Process lists (or queues) • running queue (single CPU) • ready queue • I/O queues • PCB (Process Control Block) • register context • process state • for context switching
PCB in xv6 Kernel struct context { // registers saved/restored in context switch inteip; intesp; intebx; intecx; intedx; intesi; intedi; intebp; }; enumproc_state// process state { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; structproc { // PCB char *mem; uintsz; char *kstack; enumproc_statestate; intpid; structproc *parent; void *chan; intkilled; structfile *ofile[NOFILE]; structinode *cwd;structcontext context; structtrapframe *tf; };