42
Discussion Week 4 TA: Kyle Dewey

Discussion Week 4

  • Upload
    arnaud

  • View
    27

  • Download
    0

Embed Size (px)

DESCRIPTION

Discussion Week 4. TA: Kyle Dewey. Overview. Project #1 debriefing System calls Project #2. Task 1 Bugs/Ugliness. About that Project. I’m not actually grading anything (probably) Clarity is a wonderful thing I apologize for any incorrect information - PowerPoint PPT Presentation

Citation preview

Page 1: Discussion Week 4

Discussion Week 4TA: Kyle Dewey

Page 2: Discussion Week 4

Overview

•Project #1 debriefing

•System calls

•Project #2

Page 3: Discussion Week 4

Task 1 Bugs/Ugliness

Page 4: Discussion Week 4

About that Project...

•I’m not actually grading anything (probably)

•Clarity is a wonderful thing

•I apologize for any incorrect information

•Output is not the same with semaphores

•Please output information in laundromat

Page 5: Discussion Week 4

System Calls

Page 6: Discussion Week 4

Why Operating Systems?

•Multitasking

•Resource management

•CPU

•Memory

•Disks

•Printers...

Page 7: Discussion Week 4

Abstraction

•“I just want to print!”

•Lots of different, very similar hardware

•Unify with a common interface

Page 8: Discussion Week 4

Isolation

•Each process “thinks” it is the only one on the system

•Each has access to resources

Page 9: Discussion Week 4

Total Resource Access

•Process A prints “Hello world!”

•Process B prints “Goodbye cruel world!”

Hello woGoodbye crld!ruel world!

Page 10: Discussion Week 4

Mediated Access

•Gain access through another entity

•The entity makes sure everything is isolated

Page 11: Discussion Week 4

Mediated Access•Process A prints “Hello world!”

•Process B prints “Goodbye cruel world!”

Hello world!Goodbye cruel world!

Page 12: Discussion Week 4

“Entity”

•The entity is the OS

•The pathway for mediation is a system call

•System calls allow processes to communicate with the OS

Page 13: Discussion Week 4

Syscall Frequency

•Any I/O (network, disk, ...)

•Any process manipulation

•Interprocess communication

•Shared library access

•Essentially access to any shared resource

Page 14: Discussion Week 4

Tools

•strace: Linux tool for intercepting syscalls

•truss: Solaris/BSD tool for intercepting syscalls

•Usage: strace ./a.out

Page 15: Discussion Week 4

“Useless” C Program

Page 16: Discussion Week 4

C Hello World

Page 17: Discussion Week 4

Java Hello World (Note -F -f was

needed)

Page 18: Discussion Week 4

Python Hello World

Page 19: Discussion Week 4

The Point

•Syscalls are made all over the place

•Rarely, if ever, directly called in actual code

•Unwieldy

•Layer of abstraction

Page 20: Discussion Week 4

System Call Execution

read()read()

User Space

Kernel Space

read()read() readFromDisreadFromDisk()k()

read()read()

Page 21: Discussion Week 4

Why Kernel Space?

•Kernel executes call “on behalf” of a process

•If a normal process could do it, then there is no isolation

•Possible to have more than just “kernel level” and “user level”

Page 22: Discussion Week 4

Something in Between -

Microkernels

•Goal: put as much of the kernel as possible in user space

•Turns out a lot can be done in user space

Page 23: Discussion Week 4

Microkernel

Page 24: Discussion Week 4

Project #2 Part 1

Page 25: Discussion Week 4

Basic Idea

•Implement system calls for basic process and file manipulation

•Note that “basic” means the base of everything - not simple!

Page 26: Discussion Week 4

Syscall Naming in NACHOS

•Names shared with threads implementation

•These are very different, though you may need the corresponding thread operations

Page 27: Discussion Week 4

Fork( func )

•Copies address space of caller

•Creates a new process in this copied address space

•Executes the given function, with this new process in the new address space

•Note the dissimilarity to UNIX’s fork()

Page 28: Discussion Week 4

Fork() Example

Page 29: Discussion Week 4

Yield()

•Temporary yields the calling process to any other processes available to run

Page 30: Discussion Week 4

Exit( int )

•Terminates the calling thread

•The parameter is the exit status (ignored for this project)

Page 31: Discussion Week 4

Exec( filename )

•Spawns a new process

•Executes the code specified in filename using the new process

•Note this does not clobber the calling process, as it does with UNIX

Page 32: Discussion Week 4

Join( SpaceId )

•Waits for the process with the given SpaceId

•The calling process blocks until the process backing SpaceId returns

Page 33: Discussion Week 4

Project #2 Part 2

Page 34: Discussion Week 4

NACHOS Filesystem

•Under Linux, it’s simply a single big file

•Under NACHOS, it contains NACHOS’ directory hierarchy

•Unless otherwise mentioned, the slides refer to the NACHOS hierarchy

Page 35: Discussion Week 4

UNIX Similarity

•NACHOS is modeled after UNIX

•Some files are actually device interfaces

Page 36: Discussion Week 4

Filesystem Stubs

•Some stubs are provided that may help

•Extremely basic and limited

•May need to scrap entirely

Page 37: Discussion Week 4

Create( name )

•Create a new, empty file with the given name

•Note that you need to be able to extend file lengths - FileSystem::Create indicates an issue with this

Page 38: Discussion Week 4

Open( name )

•Opens the file with the given name

•Returns NULL if it does not exist

Page 39: Discussion Week 4

Close( OpenFileId )

•Closes the file denoted by the given open file ID

Page 40: Discussion Week 4

ReadAt( buffer, size, pos )

•Reads size bytes starting at pos into buffer

•Note that this is a method on the OpenFile object

Page 41: Discussion Week 4

WriteAt( buffer, size, pos )

•Write size bytes from buffer, starting at pos

•Note that this is a method on the OpenFile object

Page 42: Discussion Week 4

Project #2 Notes

•Far more provided detail

•Well-defined outputs

•Due November 8 at midnight

•Much more difficult than project #1 (worth twice as much, too)