Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.

Similar presentations


Presentation on theme: "Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software."— Presentation transcript:

1 Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software Engineering University of Wisconsin-Platteville

2 Outlines process process creation/termination context
process control block (PCB) context switch 5-state process model process scheduling short/medium/long term Unix process model

3 Process Process (also called task, or job) is a program in execution
A process includes: Program code (or text) sequence of instructions to be executed note: multiple processes may be running the same code (editor, web-browser, etc) Program counter Stack Data section Context (execution state)

4 Process Creation One process (parent) can create another process (child) Why: child to do some work for parent Child: identical copy of parent (same code, same data, etc.) Parent: can either wait for the child to complete, or continue executing in parallel (concurrently) with the child parent does not terminate until the child does Unix: Fork() system call creates new process child often uses exec( ) to start another completely different program

5 Unix Example #include <sys/types.h> #include <stdio.h>
To compile on aegis: gcc -o fork fork.c Draw picture below and explain carefully Parent Child a a b b code code pid = fork( ) pid = fork ( ) /* gets pid of 0 */ wait( ) a++ b++ printf /* prints second */ printf /* prints first */ wait( ) = wait until specified process (child here) finishes Understand why only one “before”, two “after”s?? It’s crucial that you understand this! What happens if I replace wait(pid) with “sleep(2)”, sleep 2 seconds child prints its “after” first, probably What happens if I drop the “else” clause? Either one of the two “after”s could happen first — no way to tell What if we want to make sure that one finishes first? Synchronization — next week… #include <sys/types.h> #include <stdio.h> int a = 6; /* global (external) variable */ int main(void) { int b; /* local variable */ pid_t pid; /* process id */ b = 88; printf("before fork\n"); pid = fork(); if (pid == 0) { /* child */ a++; b++; } else /* parent */ wait(pid); printf("after fork, a = %d, b = %d\n", a, b); exit(0); } System call fork() returns the child process ID to the parent and returns 0 to the child process before fork after fork, a = 7, b = 89 after fork, a = 6, b = 88

6 Process Termination Process executes last statement and asks the operating system to decide it (exit). Output data from child to parent (via wait). Process’ resources are deallocated by operating system. Parent may terminate execution of children processes (abort). Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting. Operating system does not allow child to continue if its parent terminates. Cascading termination.

7 Context Context – information about running process
program code (.text) static data (.bss) heap (dynamic data) procedure call stack - contains temporary data - subroutine parameters, return addresses, local variables register contents general purpose registers program counter (PC) — address of next instruction to be executed stack pointer (SP) program status word (PSW) — interrupt status, condition codes, etc. OS resources in use - open files, connections to other programs accounting information program memory allocation Where do these processes come from? 1. These first two are user processes 2. OS on behalf of user 3. OS daemons (not shown here) How do they end?

8 Process Control Block (PCB)
Information associated with each process Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

9 Five State Process Model
OS maintains the state of a process New: The process is being created. Running: Instructions are being executed. Waiting (blocked): The process is waiting for some event to occur. Ready: The process ready to run on the CPU. Terminated: The process has finished execution.

10 Context Switching Context switch : stopping one process and restarting another Sequence of actions: OS takes control (through interrupt) saves old context in the process PCB reloads new context from the new process PCB returns control to app. program

11 Process Scheduling Queues
Process migration between the various queues Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, ready and waiting to execute Device queues – set of processes waiting for an I/O device

12 Process Scheduler Long-term scheduler (or job scheduler)
Medium-term scheduler Short-term scheduler (or CPU scheduler)

13 Representation of Process Scheduling

14 CPU Scheduler Short-term scheduler
Selects process from the ready queue to run on the CPU runs when process is created or terminated process switches from running to blocked interrupt occurs Goals minimize response time maximize throughput fairness — share CPU in an equitable fashion efficient use of system resources

15 Job Scheduler Long-term scheduler
selects job from the spool, and loads it into memory runs when A process leaves system Goals good mix of CPU-bound and I/O-bound processes 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 very long CPU bursts

16 Medium-term Scheduler
Temporarily swaps processes in/out of main memory may suspend/resume processes goal: balance load for better throughput

17 Modes of Execution User mode System mode, control mode, or kernel mode
Less-privileged mode User programs typically execute in this mode System mode, control mode, or kernel mode More-privileged mode Kernel of the operating system

18 Execution of the Operating System
Non-process Kernel execute kernel outside of any process operating system code is executed as a separate entity that operates in privileged mode Execution Within User Processes operating system software within context of a user process process executes in privileged mode when executing operating system code

19 Unix State Process Model
Unix process states: created - just created not yet ready to run ready (memory) - ready as soon as kernel schedules it ready (disk) - ready, but needs to be swapped to memory asleep - blocked (memory) - waiting on event in memory asleep - blocked (disk) - waiting on event on disk running (kernel) - executing in kernel mode running (user) - executing in user mode zombie - process terminated but left a record for parent to collect


Download ppt "Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software."

Similar presentations


Ads by Google