1 / 18

CS222

Week 4 - Friday. CS222. Last time. What did we talk about last time? We had snow days… But you should have read about break , continue , and goto System programming Functions Scope Compiling with multiple files. Questions?. Project 2 . Quiz. Quotes. Unix never says "please."

argyle
Download Presentation

CS222

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 4 - Friday CS222

  2. Last time • What did we talk about last time? • We had snow days… • But you should have read about • break, continue, and goto • System programming • Functions • Scope • Compiling with multiple files

  3. Questions?

  4. Project 2

  5. Quiz

  6. Quotes Unix never says "please." Rob Pike • It also never says: • "Thank you" • "You're welcome" • "I'm sorry" • "Are you sure you want to do that?"

  7. The register modifier • You can also use the register keyword when declaring a local variable • It is a sign to the compiler that you think this variable will be used a lot and should be kept in a register • It's only a suggestion • You can not use the reference operator (which we haven't talked about yet) to retrieve the address of a register variable • Modern compilers are better at register allocation than humans usually are register intvalue;

  8. Processes

  9. Processes • Recall that a process is a running program • Multiple copies of a single program can be running as different processes • A program is a binary file (generated by the compiler) • Formats used to be: • Assembly output (where the name a.out comes from) • COFF (Common Object File Format) • Now they are usually ELF (Executable and Linking Format) • Details about binary formats are more interesting when you're writing a compiler

  10. PIDs • Every running process has a process ID (PID) • You can find out the PID of the currently executing code by calling the getpid() function • Every process also has a parent process (which has a parent PID) • Get that by calling getppid() • The parent is the process that created the current process • This parent-child relationship forms a tree all the way back to the first process init, which always has PID 1

  11. Process memory segments • Layout for 32-bit architecture • Could only address 4GB • Modern layouts often have random offsets for stack, heap, and memory mapping for security reasons Kernel Space 1GB Only for Linux kernel Memory for function calls Addresses for memory mapped files Dynamically allocated data Uninitialized globals Initialized globals Program code 0xc0000000 Stack Memory Mapping 0x40000000 3GB Heap BSS Data Text 0x08048000 0x00000000

  12. Virtual memory • Those addresses (from 0 to 4GB) are virtual addresses • Each program sees an address space stretching from 0 to 4GB • The OS transparently manages how those addresses are mapped to physical memory • The virtual address space is divided up into pages • Each page can be in memory or sitting on disk • Pages are typically moved into memory only when needed

  13. Why virtual memory? • It isolates processes from each other • Since they have different address spaces, it is harder for one program to read the data out of another • Processes can share the same memory without inadvertently trampling on each other • Since paging is controlled by the OS, pages can be marked read-only • Programmers don't need to worry about the actual layout of memory • Programs can load faster because only part of them needs to be put into RAM

  14. Process commands • ps gives a snapshot of the current processes running • top gives repeatedly updated information about the processes running • The kill command lets you end a process • You have to have sufficiently high privileges to do so

  15. Lab 4

  16. Upcoming

  17. Next time… • Arrays

  18. Reminders • Read K&R chapter 5 • Keep working on Project 2

More Related