October 7, 2002 Gary Kimura Lecture #4 October 7, 2002

Slides:



Advertisements
Similar presentations
Processes and Threads Prof. Sirer CS 4410 Cornell University.
Advertisements

CSE 451: Operating Systems Winter 2007 Module 4 Processes Ed Lazowska Allen Center 570.
IT344 – Operating Systems Winter 2011, Dale Rowe.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
Processes CSCI 444/544 Operating Systems Fall 2008.
CSE 451: Operating Systems Winter 2009 Module 4 Processes Mark Zbikowski Gary Kimura.
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.
CSE451 Processes Spring 2001 Gary Kimura Lecture #4 April 2, 2001.
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?
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska Allen Center 570.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CSE 451: Operating Systems Winter 2012 Processes Mark Zbikowski Gary Kimura.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Implementing Processes and Process Management Brian Bershad.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Computer Studies (AL) Operating System Process Management - Process.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
CSE 451: Operating Systems Spring 2010 Module 4: Processes John Zahorjan Allen Center 534.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Processes.
Lecture Topics: 11/1 Processes Process Management
Process Management Presented By Aditya Gupta Assistant Professor
CSE 451: Operating Systems Autumn 2013 Module 4 Processes
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
IT 344: Operating Systems Module 4 Processes
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Lecture 2: Processes Part 1
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process & its States Lecture 5.
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2011 Processes
CSE 451: Operating Systems Winter 2010 Module 4 Processes
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes Hank Levy 1.
Processes and Process Management
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Autumn 2009 Module 4 Processes
IT 344: Operating Systems Winter 2008 Module 4 Processes
CSE 451: Operating Systems Winter 2007 Module 4 Processes
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
CSE 451: Operating Systems Spring 2006 Module 4 Processes
CSE 153 Design of Operating Systems Winter 2019
Processes Hank Levy 1.
CSE 451: Operating Systems Autumn 2010 Module 4 Processes
Presentation transcript:

October 7, 2002 Gary Kimura Lecture #4 October 7, 2002 CSE451 Processes Autumn 2002 Gary Kimura Lecture #4 October 7, 2002 CSE 451 Introduction to Operating Systems

Today Finish up with Micro-kernels Quick review (our road map) Processes Processes the basic computational “object” of the OS Conceptually What formally makes up a process? What does a process do (more importantly what does an OS do to a process) Nuts and bolts The usual round of data structures and code behind the concept

But First, Your Job for Week #2 Readings in Silberschatz Chapter 4 (Monday) Chapter 5 (Wednesday) Chapter 6 (Friday) Work on project #1

What have we looked at so far What is an OS when it is all put together and what does it do? What tools are available to build the OS? (i.e., the hardware) What are the big pieces we need build and how do we stick them together? (i.e., how do we organize the insides)

Process Management Process management is the task of shepherding programs through the OS gauntlet. In process management there are several issues we need to deal with: What is the basic entity involved (i.e., the units of execution) How are those entities represented in the OS How is work scheduled in the CPU What are possible execution states, and how does the system move from one to another The term process, not surprisingly is the name we use to encapsulate this basic entity.

The Process Basic idea behind the process is that A process is the unit of execution, it represents a running program in the system It is also the unit of scheduling and resource allocation in the OS. Meaning the OS typically allocates resources to a process It is the dynamic (active) execution context (as opposed to a program, which is static) A process is sometimes called a job or a task or a sequential process. A sequential process defines the instruction-at-a-time execution of a program

What’s in a Process? A process consists of (at least): an address space the code for the running program the data for the running program an execution stack and stack pointer (SP) traces state of procedure calls made the program counter (PC), indicating the next instruction a set of general-purpose processor registers and their values a set of OS resources open files, network connections, sound channels, … The process is a container for all of this state a process is named by a process ID (PID) just an integer (actually, typically a short)

A process’s address space 0x7FFFFFFF† stack (dynamic allocated mem) SP heap (dynamic allocated mem) address space static data (data segment) code (text segment) PC 0x00000000 †Note: only 31 bits are used. Later in the class we’ll see why this is often the case.

Process states Each process has an execution state, which indicates what it is currently doing ready: waiting to be assigned to CPU could run, but another process has the CPU running: executing on the CPU is the process that currently controls the CPU pop quiz: how many processes can be running simultaneously? waiting: waiting for an event, e.g. I/O cannot make progress until event happens As a process executes, it moves from state to state

Process state transitions create New Ready I/O done unschedule Waiting schedule kill Terminated Running I/O, page fault, etc. What can cause transitions?

Process data structures How does the OS represent a process in the kernel? at any time, there are many processes, each in its own particular state the OS data structure that represents each is called the process control block (PCB) PCB contains all info about the process OS keeps all of a process’ hardware execution state in the PCB when the process isn’t running PC SP registers when process is unscheduled, the state is transferred out of the hardware into the PCB

PCB The PCB contains lots of information, e.g.: process state process number program counter stack pointer 32 general-purpose registers memory management info username of owner queue pointers for state queues scheduling info (priority, etc.) accounting info

PCBs and Hardware State When a process is running, its hardware state is inside the CPU PC, SP, registers CPU contains current values When the OS stops running a process (puts it in the waiting state), it saves the registers’ values in the PCB when the OS puts the process in the running state, it loads the hardware registers from the values in that process’ PCB The act of switching the CPU from one process to another is called a context switch timesharing systems may do 100s or 1000s of switches/second takes about 5 microseconds on today’s hardware

State Queues The OS maintains a collection of queues that represent the state of all processes in the system. There is typically one queue for each state, e.g., ready, waiting for I/O, etc. Each PCB is queued onto a state queue according to its current state. As a process changes state, its PCB is unlinked from one queue and linked onto another.

State Queues (Continued) PCB A PCB W PCB G Ready Queue Header head ptr tail ptr Wait Queue Header head ptr PCB X PCB M tail ptr There may be many wait queues, one for each type of wait (specific device, timer, message,…).

Process creation One process can create another process creator is called the parent created process is called the child UNIX: do ps, look for PPID field what creates the first process, and when? In some systems, parent defines or donates resources and privileges for its children UNIX: child inherits parents userID field, etc. when child is created, parent may either wait for it to finish, or it may continue in parallel, or both!

UNIX process creation UNIX process creation through fork() system call creates and initializes a new PCB creates a new address space initializes new address space with a copy of the entire contents of the address space of the parent initializes kernel resources of new process with resources of parent (e.g. open files) places new PCB on the ready queue the fork() system call returns twice once into the parent, and once into the child returns the child’s PID to the parent returns 0 to the child

fork( ) int main(int argc, char **argv) { char *name = argv[0]; int child_pid = fork(); if (child_pid == 0) { printf(“Child of %s is %d\n”, name, child_pid); return 0; } else { printf(“My child is %d\n”, child_pid); }

output spinlock% gcc -o testparent testparent.c spinlock% ./testparent My child is 486 Child of testparent is 0

Fork and exec So how do we start a new program, instead of just forking the old program? the exec() system call! int exec(char *prog, char ** argv) exec() stops the current process loads program ‘prog’ into the address space initializes hardware context, args for new program places PCB onto ready queue note: does not create a new process! what does it mean for exec to return? what happens if you “exec csh” in your shell? what happens if you “exec ls” in your shell?

UNIX shells int main(int argc, char **argv) { while (1) { char *cmd = get_next_command(); int child_pid = fork(); if (child_pid == 0) { manipulate STDIN/STDOUT/STDERR fd’s exec(cmd); panic(“exec failed!”); } else { wait(child_pid); }

Cooperating Processes Processes can be independent or they can be cooperating to accomplish a single job. Cooperating processes can be used: to gain speedup by overlapping activities or performing work in parallel to better structure an application as a small set of cooperating processes to share information between jobs Sometimes processes are structured as a pipeline where each produces work for the next stage that consumes it, and so on.

Next time Processes are nice, but threads are dandy