Operating Systems Processes Maria Hybinette, UGA Maria Hybinette, UGA Review • Operating System Fundamentals – What is an OS? – What does it do? – How and when is it invoked? • Structures – Monolithic – Layered – Microkernels – Virtual Machines – Modular Maria Hybinette, UGA Maria Hybinette, UGA
Chapter 3: Processes: Outline • Process Concept: Views of a Process • Process Basics Scheduling Principles • Process Operations – Life of a process: from birth to death … • Cooperating Processes (later) – Inter Process Communication – local and remote • Mailboxes • Shared Memory • Remote Procedure Calls • Sockets (briefly – since it is covered networking classes) • Pipes • Files Maria Hybinette, UGA Maria Hybinette, UGA What is a Process? 1. Place in Memory 2. Start Running • A program in execution • An activity • A running program. – Basic unit of work on a computer, a job, or a task. – A container of instructions with Simplification some added resources: • CPU time (CPU carries out PROCESS Examples: the instructions), compilation process, SET OF word processing processes, • memory, files, scheduler ( sched , swapper ) process, • I/O devices to accomplish its daemon processes: ftpd, httpd task Maria Hybinette, UGA Maria Hybinette, UGA
What are Processes? System’s Point View: • Multiple processes – Several distinct processes executing. • Note: Several distinct processes can execute the SAME program • Time sharing systems run several processes by multiplexing between them (scheduler manages the multiplexing). • ALL “run”-able processes including the OS are organized into a number of “sequential processes ” Processes n-1 … Scheduler Maria Hybinette, UGA Maria Hybinette, UGA Virtualization User’s Point of View: • Processor ! Virtual Processor – Illusion of monopolizing the processor • Memory ! Virtual Memory – Address space! Really – more than just memory. – Illusion of monopolizing address space; or access of all memory of the system and open files and other resources. Maria Hybinette, UGA Maria Hybinette, UGA
Process Definition (slightly formal) Processor A process is a ‘program in execution’, a sequential execution characterized by trace. It has a context (the information or data) and this ‘context’ is maintained as the process progresses through the system. Address Space Maria Hybinette, UGA Maria Hybinette, UGA 1 CPU Activity of a Process A Process A B Process B Process C C Time Multiprogramming ? How? • Solution : Provide a programming counter. • One processor (CPU). Gives an illusion that each process has its own processor. Maria Hybinette, UGA Maria Hybinette, UGA
Activity of a Process: Time Sharing Illusion of monopoly A B C Process A Process B Process C Time Maria Hybinette, UGA Maria Hybinette, UGA Enabling “Processing” Investigate : What Does the Process Really Do? • Begin : It is created! – Runs – Does not run (but ready to run) – Runs – Does not run (but ready to run) – …. • End : Terminates Maria Hybinette, UGA Maria Hybinette, UGA
‘States’ of a Process towards scheduling • As a process executes, it changes state – New: The process is being created. – Running: Instructions are being executed. – Ready: The process is waiting to be assigned to a processor (CPU). – Terminated: The process has finished execution. – Waiting: The process is waiting for some event to occur. New Terminated Ready Running Waiting Maria Hybinette, UGA Maria Hybinette, UGA State Transitions • A process may change state as a result: – Program action (system call initiated by the process) • From a running process. – OS action (scheduling decision) – External action (interrupts) Interrupt (time) and scheduler picks exit() New admitted another process Terminated Ready Running I/O or event Scheduler pick I/O or event wait completion Waiting There is at most one running process per CPU or core Maria Hybinette, UGA Maria Hybinette, UGA https://en.wikipedia.org/wiki/Multi-core_processor
OS Designer’s Questions? • How is process state represented? – What information is needed to represent a process? • How are processes selected to transition between states? • What mechanism is needed for a process to run on the CPU? Maria Hybinette, UGA Maria Hybinette, UGA What Makes up a Process? User resources/OS Resources: User Mode Address • Program code (text) Space • Data Stack routine1 – global variables var1 var2 – heap (dynamically allocated memory) Free memory • Process stack – function parameters Heap – return addresses Text – local variables and functions main routine1 • OS Resources, environment routine2 – open files, sockets Data: Static arrayA – Credential for security arrayB • Registers – program counter, stack pointer address space are the shared resources of a(ll) thread(s) in a program Maria Hybinette, UGA Maria Hybinette, UGA
What is needed to keep track of a Process? • Memory information: – Pointer to memory segments needed to Memory Limits run a process, i.e., • pointers to the address space – Page tables – text, data, stack segments. Process Number • Process management information: Program Counter – Process state, ID Registers – Content of registers: • Program counter, stack pointer, process Process State state, priority, process ID, CPU time used List of opened files • File management & I/O information: I/O Devices allocated – Working directory, file descriptors open, Accounting I/O devices allocated • Accounting : amount of CPU used. Process control Block (PCB) Maria Hybinette, UGA Maria Hybinette, UGA Process Representation Process P 2 Information System Memory Kernel Process Table Memory base Initial P 0 Program counter P 0 : HW state: resources Process P 3 … P 1 : HW state: resources Process P 2 P 2 : HW state: resources P 3 : HW state: resources Memory mappings … Pending requests Process P 1 … Maria Hybinette, UGA Maria Hybinette, UGA
OS View : Process Control Block (PCB) • How does an OS keep track of the state of a process? – Keep track of ‘some information’ in a data structure . • Example: In Linux a process’ information is kept in a structure called: • struct task_struct declared in #include linux/sched.h – What is in the structure? struct task_struct pid_t pid; /* process identifier */ long state; /* state for the process */ unsigned int time_slice /* scheduling information */ struct mm_struct *mm /* address space of this process */ • Where is it defined: – not in /usr/include/linux – only user level code – /usr/src/kernels/2.6.32-642.3.1.el6.x86_64/include/linux » (on nike). uname –a // unix name /proc/<pid> directory storing process information Maria Hybinette, UGA Maria Hybinette, UGA top & ps commands showing process information State in Linux volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 #define TASK_ZOMBIE 4 #define TASK_STOPPED 8 #define TASK_EXCLUSIVE 32 Maria Hybinette, UGA Maria Hybinette, UGA
Did someone say Zombie? • Zombies : Terminated processes waiting for a parent to read its exit state. Parent reads exit status by a wait system call. – 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 the child terminates • Reaps : Removed from the process table/resource table (after the wait call by parent). Maria Hybinette, UGA Maria Hybinette, UGA Process Table in a Microkernel (e.g., MINIX, Mach) Monolithic • Microkernel design - process table Kernel, Memory, File, Proc functionality (monolithic) partitioned Kernel Memory File Proc into four tables: – Kernel management (kernel/proc.h) – Memory management (VM server vm/vmproc.h) • Memory part of fork, exit calls • Used/unused part of memory – File management (FS) (FS server fs/fproc.h – Process management (PM server pm/mproc.h) Maria Hybinette, UGA Maria Hybinette, UGA
Running Processes 1 CPU Running Ready Waiting Process A Process B Process C Scheduler Time Maria Hybinette, UGA Maria Hybinette, UGA Why is Scheduling important? • Goals: – Maximize the ‘usage’ of the computer system – Maximize CPU usage (utilization) – Maximize I/O device usage – Meet as many task deadlines as possible (maximize throughput). HERE Maria Hybinette, UGA Maria Hybinette, UGA
Scheduling • Approach : Divide up scheduling into task levels : – Select process who gets the CPU (from main memory). – Admit processes into memory • Short-term scheduler (CPU scheduler): – Selects process to be executed next and allocates the CPU. • invoked frequently (ms) ⇒ (must be fast). • Long-term scheduler (Memory scheduler) – Selects processes allocated into the memory (ready state) – invoked “infrequently” (seconds, minutes) – controls the degree of multiprogramming. Ready Queue Maria Hybinette, UGA Maria Hybinette, UGA Process Ch Charac tf tf ris ris tj tj cs cs • Processes can be described as either: – I/O-bound process – spends more time doing I/O than computations, many short CPU bursts. – CPU-bound process – spends more time doing computations; few long CPU bursts. Maria Hybinette, UGA Maria Hybinette, UGA
Recommend
More recommend