+ All Categories
Home > Documents > 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi...

04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi...

Date post: 31-May-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
13
4. The Abstraction: The Process Operating System: Three Easy Pieces AOS@UC 1
Transcript
Page 1: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

4. The Abstraction: The ProcessOperating System: Three Easy Pieces

AOS@UC 1

Page 2: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

How to provide the illusion of many CPUs?

p CPU virtualizing

w The OS can promote the illusion that many virtual CPUs exist.

w Time sharing: Running one process, then stopping it and running another

¢ The potential cost is performance.

AOS@UC 2

Page 3: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

A Process

p Comprising of a process:

w Memory (address space)

¢ Instructions

¢ Data section

w Registers (processor architectural state (?) )

¢ Program counter

¢ Stack pointer

¢ …

AOS@UC 3

A process is a running program.

Page 4: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Process API

p These APIs are available on any modern OS.

w Create

¢ Create a new process to run a program

w Destroy

¢ Halt a runaway process

w Wait

¢ Wait for a process to stop running

w Miscellaneous Control

¢ Some kind of method to suspend a process and then resume it

w Status

¢ Get some status info about a process

w …

AOS@UC 4

Page 5: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Process Creation

1. Load a program code into memory, into the address space of the

process.

w Programs initially reside on disk in executable format (code + static data).

w OS perform the loading process lazily.

¢ Loading pieces of code or data only as they are needed during program

execution.

2. The program’s run-time stack is allocated.

w Use the stack for local variables, function parameters, and return address.

w Initialize the stack with arguments à argc and the argv array of main()

function

AOS@UC 5

Page 6: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Process Creation (Cont.)

3. The program’s heap is created.

w Used for explicitly requested dynamically allocated data.

w Program request such space by calling malloc() and free it by calling

free().

4. The OS do some other initialization tasks.

w input/output (I/O) setup

¢ Each process by default has three open file descriptors.

¢ Standard input, output and error

5. Start the program running at the entry point, namely main().

w The OS transfers control of the CPU to the newly-created process.

AOS@UC 6

Page 7: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Loading: From Program To Process

AOS@UC 7

codestatic data

heap

stack

Process

Memory

codestatic data

heap

Program

Disk

Loading:Takes on-disk programand reads it into the

address space of process

CPU

Page 8: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Process States

p A process can be one of three states.

w Running

¢ A process is running on a processor.

w Ready

¢ A process is ready to run but for some reason the OS has chosen not to run it

at this given moment.

w Blocked

¢ A process has performed some kind of operation.

¢ When a process initiates an I/O request to a disk, it becomes blocked and thus

some other process can use the processor.

AOS@UC 8

Page 9: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Process State Transition

AOS@UC 9

Running Ready

Blocked

Descheduled

Scheduled

I/O: doneI/O: initiate

Page 10: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Data structures

p The OS has some key data structures that track various relevant pieces

of information.

w Process list

¢ Ready processes

¢ Blocked processes

¢ Current running process

w Register context

p PCB(Process Control Block)

w A C-structure that contains information about each process.

AOS@UC 10

Page 11: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Example) The xv6 kernel Proc Structure

AOS@UC 11

// the registers xv6 will save and restore// to stop and subsequently restart a processstruct context {

int eip; // Index pointer registerint esp; // Stack pointer registerint ebx; // Called the base registerint ecx; // Called the counter registerint edx; // Called the data registerint esi; // Source index registerint edi; // Destination index registerint ebp; // Stack base pointer register

};

// the different states a process can be inenum proc_state { UNUSED, EMBRYO, SLEEPING,

RUNNABLE, RUNNING, ZOMBIE };

Page 12: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

Example) The xv6 kernel Proc Structure (Cont.)

AOS@UC 12

// the information xv6 tracks about each process// including its register context and statestruct proc {

char *mem; // Start of process memoryuint sz; // Size of process memorychar *kstack; // Bottom of kernel stack

// for this processenum proc_state state; // Process stateint pid; // Process IDstruct proc *parent; // Parent processvoid *chan; // If non-zero, sleeping on chanint killed; // If non-zero, have been killedstruct file *ofile[NOFILE]; // Open filesstruct inode *cwd; // Current directorystruct context context; // Switch here to run processstruct trapframe *tf; // Trap frame for the

// current interrupt};

Page 13: 04.The abtrasction the process - GitHub Pages...lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at University of Wisconsin) AOS@UC 13 Title 04.The_abtrasction_the_process

p Disclaimer: This lecture slide set is used in AOS course in University of Cantabria. Was initially

developed for Operating System course in Computer Science Dept. at Hanyang University. This

lecture slide set is for OSTEP book written by Remzi and Andrea Arpaci-Dusseau (at

University of Wisconsin)

AOS@UC 13


Recommended