Operating Systems CMPSC 473 Processes August 31, 2010 - Lecture 3 Instructor: Bhuvan Urgaonkar.

Slides:



Advertisements
Similar presentations
Chapter 3 Process Description and Control
Advertisements

CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
Processes CSCI 444/544 Operating Systems Fall 2008.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Processes and Resources
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes April 5, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Implementing Processes and Process Management Brian Bershad.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Operating Systems CMPSC 473 Processes (4) September Lecture 10 Instructor: Bhuvan Urgaonkar.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Operating Systems CMPSC 473 Processes (3) September Lecture 9 Instructor: Bhuvan Urgaonkar.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Operating Systems CMPSC 473 Processes (contd.) September 01, Lecture 4 Instructor: Bhuvan Urgaonkar.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
CSCI 4061 Recitation 2 1.
Process concept.
Operating Systems CMPSC 473
Process Management Process Concept Why only the global variables?
Processes.
Protection of System Resources
Lecture Topics: 11/1 Processes Process Management
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Structure of Processes
Processes in Unix, Linux, and Windows
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
Processes Hank Levy 1.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Lecture 6: Multiprogramming and Context Switching
October 7, 2002 Gary Kimura Lecture #4 October 7, 2002
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Process Description and Control in Unix
Processes Hank Levy 1.
Process Description and Control in Unix
Presentation transcript:

Operating Systems CMPSC 473 Processes August 31, Lecture 3 Instructor: Bhuvan Urgaonkar

Teaching Assistant Name : Ohyoung Jang Office Hour : 2:30pm ~ 4:30pm, Mon Wed Location : 338E IST 2/22

Contents Sample Program Compiling in Unix How to use gdb Makefile 3/22

Sample Program > #include void print_hello(char* name) { printf("Hello %s.\n", name); } int compute_intsum(int n) { int i; int sum = 0; for (i = 1; i <= n; i++) { sum += i; } return sum; } > #include void print_hello(char* name); int compute_intsum(int); int main(int argc, char** argv) { int sum; int n = 100; char* name1 = "Ohyoung"; char* name2 = "Another long name"; sum = compute_intsum(100); printf("sum from 1 to %d is %d\n", n, sum); print_hello(name1); strcpy(name1, name2); print_hello(name1); return 0; } 4/22

Contents Sample Program Compiling in Unix How to use gdb Makefile 5/22

Compiling in Unix Use gcc for c, or g++ for c++ to compile, link and generate executable “-c” option for compile –If omitted, gcc/g++ links object files and make executable file “-g” option for insert debug infos –To use gdb, this option is required. man(1) gcc 6/22

Compiling in Unix Use gcc for c, or g++ for c++ –Options “-Ox” option for optimization level –0 : no-optimization (required for gdb) –1-5 : optimization level. Higher number -> more opt “-I” for set include directories “-L” for setting library directories “-o” for setting output file –Infile src or object files 7/22

Compiling in Unix Example –Compile source files –Link all object files to make an executable Compile main.c with debug info with no-optimization output file is main.o Make executable with main.o and src1.o 8/22

Compiling in Unix Easier example –Compile and Link in a command 9/22

Contents Sample Program Compiling in Unix How to use gdb Makefile 10/22

How to use gdb You may face error before you use gdb –You may expect “Another long name” instead of segmantatino fault Program is terminated due to a trap Just type “gdb ” 11/22

How to use gdb gdb console Output of the program Program terminated. But process infos remains. Then type “bt” or “backtrace” 12/22

How to use gdb Print variable Error. Current frame is 0 Call stack with frame number Change from to 1 Print variable The bug is found 13/22

How to use gdb Another GDB commands –help [command] –b(reak) : set breakpoint b : [condition] b [condition] –Ex) b src1.c:15 if i == 10 –Ex) b compute_intsum –info b(reak) : list breakpoints –delete 14/22

How to use gdb Another GDB commands –r(un) [argument] Start program –s(tep) Step program until it reaches a different src line –n(ext) Like “step” command, as long as subroutine calls do not happen –c(ontinue) Continue program until breakpoints or signals 15/22

16/22

Contents Sample Program Compiling in Unix How to use gdb Makefile 17/22

Makefile The “make” utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.[1] To use “make” utility, we need “Makefile” file. Makefile is consisted of variables and rules 18/22

Makefile Usage –To build $make [build] –To clean $make clean –To rebuild $make rebuild > CC = gcc CFLAGS = -O0 -g OBJS = main.o \ src1.o TARGET=test build: $(OBJS) gcc -o $(TARGET) $(OBJS) rebuild: clean build clean: rm -rf $(OBJS) rm -rf $(TARGET) Variables Rules 19/22

Makefile > CC = gcc CFLAGS = -O0 -g OBJS = main.o \ src1.o TARGET=test build: $(OBJS) gcc -o $(TARGET) $(OBJS) rebuild: clean build clean: rm -rf $(OBJS) rm -rf $(TARGET) Define Rules : \t.. Predefined Rules %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o Automatic Variables %< : The name of the first prerequisite : The name of the target 20/22 Define Rules : \t..

Makefile 21/22

Reference [1] manual/make.html 22/22

Last class Interrupts, traps, signals Introduction to processes –Address space –Process life-cycle

Tutorial on gdb

Project 1

Process Control Block (PCB) Process state Process id (PID) Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information Process state... Process id Program counter CPU registers Memory limits List of open files today later

CPU switch among processes

Enumerating # Possible CPU Multiplexing Between Processes Consider two processes P1 and P2 –P1: n instructions –P2: m instructions –No jump instrictions => No loops How many unique executions are possible?

Data structs associated with PCBs Queue of ready (runnable) processes –Scheduler picks from these Queues of waiting (blocked) processes –Sepearate queues for difference devices Sometimes PCB of exited process kept in memory –Pop quiz: Why? All PCBs in a part of RAM reserved by the kernel for itself and inaccessible to processes –This part of RAM initialized during boot-up

Data Structure #1: PCB Can PCBs be swapped out? –Depends on the OS design.. so sometimes YES Process id Program Counter … Other registers Process state Ptr to linked list Main Memory (RAM) OS Processes

Ready Waiting Running Disk Lock

Ready Waiting Running Disk Lock Timer interrupt

Ready Waiting Running Disk Lock

Ready Waiting Running Disk Lock I/O call

Ready Waiting Running Disk Lock OS (scheduler) Lets pick the second process in the ready queue

Modern Kernels are Re-entrant Note: Not showing scheduler invocations A re-entrant kernel is able to suspend the current running process even if it is in the Kernel Mode –Several processes may be in Kernel Mode at the same time Usually one or more “kernel mode stacks” used when in kernel mode –Kept in kernel’s address space Process 1 USER MODE KERNEL MODE Process 1Process 2 Time ExcpIntr Kernel control paths One KCP

Re-entrant Kernels Note: Not showing scheduler invocations Why re-entrancy? –Improves throughput of devices controllers that raise interrupts –Allows priorities among interrupts Process 1 USER MODE KERNEL MODE Process 1Process 2 Time ExcpIntr Kernel control paths One KCP

Relationships among processes Several relatives of P recorded in its PCB –real_parent Process that called fork to create P Or init (process 1) –parent Usually real_parent –Kernel signals this parent process when child exits Or process that issues ptrace () to monitor P Pop quiz: If you run a background process and exit the shell, who is the parent of the process? –children –siblings Why maintain these?

Creating Processes fork () Take 1: Used in older kernels –Create a copy of the entire address space of the parent –Create a new PCB for the new process –Update parent, children, sibling pointers –Place the new process in the ready queue S. L. O. W.

Id=2000 State=ready PCB of parent RAM OS Processes Parent’s memory Process calls fork Id= PCB with new id created 2. Memory allocated for child Initialized by copying over from the parent Child’s memory 3. If parent had called wait, it is moved to a waiting queue 4. If child had called exec, its memory overwritten with new code & data 5. Child added to ready queue, all set to go now! State=ready PCB of child

Creating Processes fork () Problems with Take 1 –Child rarely needs to read/modify ALL the resources inherited from the parent –Often, it immediately issues an execve() rendering all the effort that went into copying the address space useless!

Creating Processes: COW fork () What modern kernels do to avoid this waste of precious CPU time –Use Copy-On-Write –Basic idea: Postpone work till the last minute –Sounds familiar? Think assignments, quizzes, …

Process Switch Suspend the current process and resume a previously suspended process –Also called context switch or task switch

Process Switch Process 0 Process 1 A1 A2 B1 B2 B3 B4 Context_switch() { } Involuntary/Voluntary

Process Switch What does the kernel need to save when suspending a process? –Hint: The entire address space is already saved (either in memory or on swap space). What else would the process need when it has to be resumed? –CPU registers This is called the hardware context of the process Execution context, PC, pointers to elements within address space, page table, etc.

Context_switch() { push R0, R1, …// save regs on its stack PCB[curr].SP = SP // save stack pointer PCB[curr].PT = PT // save ptr(s) to address space next = schedule() // find next process to run PT = PCB[next].PT SP = PCB[next].SP pop Rn, … R0 return// NOTE: Ctrl returns to another process }

Overheads of Process Switch Direct –The time spent switching context Indirect –Cache pollution –TLB flush