Review ● Operating System Fundamentals CSCI 6730 / 4730 » What is an OS? Operating Systems » What does it do? » How and when is it invoked? ● Structures Processes » Monolithic » Layered » Microkernels » Virtual Machines » Modular 2 Maria Hybinette, UGA Maria Hybinette, UGA Chapter 3: Processes: Outline What is a Process? ● A program in execution ● Process Concept: views of a process ● An activity ● Process Basics Scheduling Principles ● A running program. ● Operations on Processes » Basic unit of work on a » Life of a process: from birth to death … computer, a job, or a task. ● Cooperating Processes (Thursday) » A container of instructions with some resources: » Inter process Communication – e.g. CPU time (CPU carries – Mailboxes out the instructions), Examples: compilation process, – Shared Memory word processing process, scheduler memory, files, I/O devices ( sched , swapper ) process or daemon – Sockets to accomplish its task processes: ftpd, http 3 4 Maria Hybinette, UGA Maria Hybinette, UGA
What are Processes? Process Definition System View: A process is a � program in execution � , a ● Multiple processes: sequential execution characterized by trace. It » Several distinct processes can execute the SAME has a context (the information or data) and program ● Time sharing systems run several processes by this � context � is maintained as the process multiplexing between them progresses through the system. ● ALL � runnables � including the OS are organized into a number of � sequential processes � Processes n-1 … Scheduler 5 6 Maria Hybinette, UGA Maria Hybinette, UGA Activity of a Process Activity of a Process: Time Sharing 1 CPU A Process A A B C B Process B Process C C Process A Time Multiprogramming: Process B ● Solution: provide a programming counter. ● One processor (CPU). Process C 7 8 Time Maria Hybinette, UGA Maria Hybinette, UGA
What Does the Process Do? � States � of a Process ● As a process executes, it changes state ● Created » New: The process is being created. » Running: Instructions are being executed. ● Runs » Ready: The process is waiting to be assigned to a ● Does not run (but ready to run) processor (CPU). » Terminated: The process has finished execution. ● Runs » Waiting: The process is waiting for some event to occur. ● Does not run (but ready to run) ● … . New Terminated ● Terminates Ready Running Waiting 9 10 Maria Hybinette, UGA Maria Hybinette, UGA State Transitions OS Designer � s Questions? ● A process may change state as a result: ● How is process state represented? » Program action (system call) » What information is needed to represent a process? » OS action (scheduling decision) ● How are processes selected to transition » External action (interrupts) between states? ● What mechanism is needed for a process to run on the CPU? Interrupt (time) and New admitted Terminated scheduler picks exit another process Ready Running Scheduler pick I/O or event I/O or event wait completion Waiting 11 12 Maria Hybinette, UGA Maria Hybinette, UGA
What Makes up a Process? What is needed to keep track of a Process? User resources/OS Resources: User Mode ● Memory information: Address Memory Limits ● Program code (text) Space » Pointer to memory segments needed heap ● Data Page tables to run a process, i.e., pointers to the address space -- text, data, stack » global variables Process Number segments. » heap (dynamically allocated memory) ● Process management information: Program Counter routine1 ● Process stack var1 » Process state, ID var2 » function parameters Registers stack » Content of registers: » return addresses main – Program counter, stack pointer, Process State text » local variables and functions routine1 process state, priority, process ID, routine2 CPU time used List of opened files ● OS Resources, environment ● File management & I/O information: data arrayA » open files, sockets I/O Devices allocated arrayB » Working directory, file descriptors » Credential for security open, I/O devices allocated Accounting ● Registers ● Accounting: amount of CPU used. » program counter, stack pointer Process control address space are the shared resources Block (PCB) 13 14 of a(ll) thread(s) in a program Maria Hybinette, UGA Maria Hybinette, UGA OS View: Process Control Block (PCB) Process Representation Process P 2 Information ● How does an OS keep track of the state of a System Memory process? » Keep track of � some information � in a structure. Kernel Process Table Memory base Initial P 0 – Example: In Linux a process � information is kept in a Program counter structure called struct task_struct declared in P 0 : HW state: resources Process P 3 #include linux/sched.h … P 1 : HW state: resources – What is in the structure? Process P 2 struct task_struct P 2 : HW state: resources pid_t pid; /* process identifier */ P 3 : HW state: resources long state; /* state for the process */ Memory mappings unsigned int time_slice /* scheduling information */ struct mm_struct *mm /* address space of this process */ … – Where is it defined: Pending requests Process P 1 ● not in /usr/include/linux – only user level code … ● /usr/src/kernels/2.6.32-642.3.1.el6.x86_64/include/linux 15 16 » (on nike). Maria Hybinette, UGA Maria Hybinette, UGA
Process Table in Microkernel (e.g., MINIX) State in Linux volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ ● Microkernel design - process table functionality (monolithic) partitioned into four #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 tables: #define TASK_UNINTERRUPTIBLE 2 #define TASK_ZOMBIE 4 » Kernel management (kernel/proc.h) #define TASK_STOPPED 8 #define TASK_EXCLUSIVE 32 » Memory management (VM server vm/vmproc.h) – Memory part of fork, exit etc calls – Used/unused part of memory • traditionally � zombies � are child processes of parents that have not » File management (FS) (FS server fs/fproc.h processed a wait() instruction. » Process management (PM server pm/mproc.h) • Note: processes that have been � adopted � by init are not zombies (these are children of parents that terminates before the child). Init automatically calls wait() on these children when they terminate. • this is true in LINUX. • What to do: 1) Kill the parent 2) Fix the parent (make it issue a wait) 2) Don � t care 17 18 Maria Hybinette, UGA Maria Hybinette, UGA Running Processes 1 CPU Why is Scheduling important? Running ● Goals: Ready » Maximize the � usage � of the computer system Waiting Process A » Maximize CPU usage (utilization) » Maximize I/O device usage Process B » Meet as many task deadlines as possible (maximize Process C throughput). Scheduler Time HERE 19 20 Maria Hybinette, UGA Maria Hybinette, UGA
Scheduling Process Characteristics ● Approach: Divide up scheduling into task levels: ● Processes can be described as either: » Select process who gets the CPU (from main memory). » I/O-bound process – spends more time doing I/ » Admit processes into memory O than computations, many short CPU bursts. – Sub problem: How? » CPU-bound process – spends more time doing ● Short-term scheduler (CPU scheduler): computations; few very long CPU bursts. » selects which process should be executed next and allocates CPU. » invoked frequently (ms) ⇒ (must be fast). ● Long-term scheduler (look at first): » selects which processes should be brought into the memory (and into the ready state) » invoked infrequently (seconds, minutes) » controls the degree of multiprogramming. 21 22 Maria Hybinette, UGA Maria Hybinette, UGA Observations Big Picture (so far) ● If all processes are I/O bound, the ready CPU queue will almost always be empty (little scheduling) Short term scheduler ● If all processes are CPU bound the I/O devices are underutilized Input Queue Main ● Approach (long term scheduler): � Admit � a Memory good mix of CPU bound and I/O bound Long term scheduler processes. Arriving Job 23 24 Maria Hybinette, UGA Maria Hybinette, UGA
Exhaust Memory? ● Problem: What happens when the number of processes is so large that there is not enough CPU room for all of them in memory? ● Solution: Medium-level scheduler: Short term scheduler » Introduce another level of scheduling that removes processes from memory; at some later time, the Input Queue process can be reintroduced into memory and its Main execution can be continued where it left off Memory Disk Long term Medium term » Also affect degree of multi-programming. scheduler scheduler Arriving Job 25 26 Maria Hybinette, UGA Maria Hybinette, UGA Which processes should be selected? Suspending a Process ● Processor (CPU) is faster than I/O so ● Which to suspend? all processes could be waiting for I/O ● Others? New Terminated » Swap these processes to disk to free up more memory Ready Running ● Blocked state becomes suspend state when swapped to disk Waiting » Two new states Main memory – waiting, suspend – Ready, suspend Ready, Waiting, Suspended Suspended Suspended Processes (possibly on backing store) 27 28 Maria Hybinette, UGA Maria Hybinette, UGA
Recommend
More recommend