discussion week 4
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 PresentationTRANSCRIPT
![Page 1: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/1.jpg)
Discussion Week 4TA: Kyle Dewey
![Page 2: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/2.jpg)
Overview
•Project #1 debriefing
•System calls
•Project #2
![Page 3: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/3.jpg)
Task 1 Bugs/Ugliness
![Page 4: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/4.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/5.jpg)
System Calls
![Page 6: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/6.jpg)
Why Operating Systems?
•Multitasking
•Resource management
•CPU
•Memory
•Disks
•Printers...
![Page 7: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/7.jpg)
Abstraction
•“I just want to print!”
•Lots of different, very similar hardware
•Unify with a common interface
![Page 8: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/8.jpg)
Isolation
•Each process “thinks” it is the only one on the system
•Each has access to resources
![Page 9: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/9.jpg)
Total Resource Access
•Process A prints “Hello world!”
•Process B prints “Goodbye cruel world!”
Hello woGoodbye crld!ruel world!
![Page 10: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/10.jpg)
Mediated Access
•Gain access through another entity
•The entity makes sure everything is isolated
![Page 11: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/11.jpg)
Mediated Access•Process A prints “Hello world!”
•Process B prints “Goodbye cruel world!”
Hello world!Goodbye cruel world!
![Page 12: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/12.jpg)
“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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/13.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/14.jpg)
Tools
•strace: Linux tool for intercepting syscalls
•truss: Solaris/BSD tool for intercepting syscalls
•Usage: strace ./a.out
![Page 15: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/15.jpg)
“Useless” C Program
![Page 16: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/16.jpg)
C Hello World
![Page 17: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/17.jpg)
Java Hello World (Note -F -f was
needed)
![Page 18: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/18.jpg)
Python Hello World
![Page 19: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/19.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/20.jpg)
System Call Execution
read()read()
User Space
Kernel Space
read()read() readFromDisreadFromDisk()k()
read()read()
![Page 21: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/21.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/22.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/23.jpg)
Microkernel
![Page 24: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/24.jpg)
Project #2 Part 1
![Page 25: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/25.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/26.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/27.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/28.jpg)
Fork() Example
![Page 29: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/29.jpg)
Yield()
•Temporary yields the calling process to any other processes available to run
![Page 30: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/30.jpg)
Exit( int )
•Terminates the calling thread
•The parameter is the exit status (ignored for this project)
![Page 31: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/31.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/32.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/33.jpg)
Project #2 Part 2
![Page 34: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/34.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/35.jpg)
UNIX Similarity
•NACHOS is modeled after UNIX
•Some files are actually device interfaces
![Page 36: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/36.jpg)
Filesystem Stubs
•Some stubs are provided that may help
•Extremely basic and limited
•May need to scrap entirely
![Page 37: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/37.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/38.jpg)
Open( name )
•Opens the file with the given name
•Returns NULL if it does not exist
![Page 39: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/39.jpg)
Close( OpenFileId )
•Closes the file denoted by the given open file ID
![Page 40: Discussion Week 4](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/40.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/41.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062804/56814ac8550346895db7dc05/html5/thumbnails/42.jpg)
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)