Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.

Similar presentations


Presentation on theme: "1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features."— Presentation transcript:

1 1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features

2 2 Last Time: Services & Hardware Support OS ServiceHardware Support Protection Interrupts Traps I/O Synchronization Virtual Memory Scheduling

3 3 This Time: OS Organizations & Processes OS Organizations (kernels) Processes

4 4 Monolithic Kernel Classic UNIX approach, Linux Everything in kernel +Fast -Risky

5 5 Layered OS Design +Modular, simple, portable, easy to design/debug -Communication overhead, copying, bookkeeping “THE” operating system Dijkstra

6 6 The Microkernel Approach Goal: Minimize contents of kernel Why?

7 7 Microkernel: Motivation Minimize contents of kernel: Reduces risk of crashing OS Put as much functionality as possible in user-level processes Simplifies extension, modification & customization First μ-kernel: Hydra (CMU) Current systems: Mach (also CMU), by Rick Rashid et al. (now head of MSR)

8 8 μ -kernels vs. Monolithic Kernels Past conventional wisdom: (1990’s) Mach – beautiful research idea but “failed” in practice Too slow! Linux – ugly, monolithic, but fast Today: much faster computers Mach: fast enough (Mac OS X)  Reliability, simplicity, robustness now more important than performance

9 9 OS Structures & Processes OS Organizations (kernels) Processes

10 10 Process OS manages variety of activities: User programs, batch jobs, command scripts Daemons: print spoolers, name servers, file servers, etc. Each activity encapsulated in process: Context (PC, registers, etc.) required for activity to run

11 11 Process != program Process is a running program One program may comprise many processes Many processes may run same program

12 12 OS and Processes OS manages & schedules processes Creation, deletion Resource allocation (e.g., CPU, memory) Suspension & resumption Inter-process communication Synchronization

13 13 Processes Process Concept Process States Process Scheduling Process Management Interprocess Communication

14 14 Process Concept Process – program in execution Process includes: text section: program code current activity: program counter, contents in registers stack data section heap

15 15 Processes Process Concept Process States Process Scheduling Process Management Interprocess Communication

16 16 Process States New Process being created Running Instructions being executed Waiting Process waiting for some event to occur Ready Process waiting to be assigned to a processor Terminated (duh)

17 17 Process State Diagram Transitions: Program actions (system calls) OS actions (scheduling) External events (interrupts)

18 18 Process Execution Example void main() { printf (“Hello world\n”); } 1. New 2. Ready 3. Running 4. Waiting for I/O 5. Ready 6. Running 7. Terminated

19 19 Process Data Structures Process Control Block: Tracks state OS allocates, places on queue OS deallocates on termination Lots of info: Process state Program counter CPU registers Memory-management information Accounting information I/O status information

20 20 Processes Process Concept Process States Process Scheduling Process Management Interprocess Communication

21 21 Process Scheduling Queues Job queue Set of all processes in system Ready queue Set of processes residing in main memory ready & waiting to execute Device queues Set of processes waiting for I/O device One per device Process migration between the various queues.

22 22 Process Queues Example

23 23 CPU Scheduling time

24 24 PCBs and Hardware State Switching processes: context switch Relatively expensive Time between switches (quantum) must be long enough to amortize this cost Start: OS picks ready process Loads register values from PCB Stop: OS saves registers into PCB

25 25 Process Scheduling Queuing-diagram representation:

26 26 Processes Process Concept Process States Process Scheduling Process Management Interprocess Communication

27 27 Process Creation One process can create other processes Creator = parent, new processes = children Parent can wait for child to complete, or continue in parallel UNIX: fork() used to create child processes Copies variables & registers from parent to child Only difference between parent & child: return value Parent: returns process id of child Child: returns 0

28 28 Process Creation Example Logging into UNIX creates shell process Every command typed into shell: Child of shell process (spawned by fork ) Executes command via exec Example: Type “emacs” OS forks new process exec executes emacs If followed by “&”, runs in parallel; otherwise, waits until done

29 29 Example UNIX Program: Fork

30 30 Fork Example: What happened? #include int main(){ int parentID = getpid(); char prgname[1024]; gets(prgname); int cid = fork(); if(cid == 0){ execlp(prgname, prgname, 0); printf(“I did not find program %s\n“, prgname); } else{ sleep(1); waitpid(cid, 0, 0); printf("Program %s is finished. \n"); } return 0; } Parent process: #include int main(){ int parentID = getpid(); char prgname[1024]; gets(prgname); int cid = fork(); if(cid == 0){ execlp(prgname, prgname, 0); printf(“I did not find program %s\n“, prgname); } else{ sleep(1); waitpid(cid, 0, 0); printf("Program %s is finished. \n"); } return 0; } Child process:

31 31 Parent & Child Process #include int main(){ int pid; pid = fork(); if(pid == 0){ printf("Child: My PID = %d\n", getpid()); printf("Child: Running...\n"); sleep(20); printf("Child: Done sleeping, returning.\n"); } else{ printf("Parent: My PID = %d\n", getpid()); printf("Parent: Running...\n"); sleep(10); printf("Parent: Done sleeping, returning.\n"); } return 0; }

32 32 Process Termination On termination, OS reclaims all resources assigned to process UNIX processes: Can terminate self via exit system call Can terminate child via kill system call

33 33 Example: Process Termination

34 34 Processes Process Concept Process States Process Scheduling Process Management Interprocess Communication

35 35 Cooperating Processes Cooperating processes: one process can affect or be affected by other processes Advantages: Can improve performance by overlapping activities or performing work in parallel Can enable simpler program design Simplifies distribution Processes can live on different machines

36 36 Interprocess Communication Processes communicate in one of two ways: Message passing: Send and receive information Numerous means: sockets, pipes, etc. Shared memory: Establish mapping to named memory object Use mmap Fork processes that share this structure

37 37 Process Summary Process = unit of execution Represented by Process Control Blocks Contain process state, registers, etc. Process state: New, Ready, Waiting, Running, or Terminated One running process at a time (on a uniprocessor) Context switch when changing process executing on CPU Communicate by message passing or shared memory


Download ppt "1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features."

Similar presentations


Ads by Google