DOC PREVIEW
CORNELL CS 414 - Operating Systems Practicum

This preview shows page 1-2-17-18-19-35-36 out of 36 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 36 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 415Operating Systems PracticumSpring 2007Ari RabkinBased on slides from Oliver KennedyWho am I?Ari Rabkin ([email protected])Cornell CS Major/MEng studentSo I’ve been through 415...Office Hours: See course web page... or by appt: feel free to emailWhat do We Expect?You should know some C (or learn quickly)Six projects turned in on timeEach project builds on the previous onesCode meets specificationWorks correctly and efficientlyDon’t be afraid to ask questions!!Where are we going?Six Projects1) Cooperative Multitasking (Thread basics)2) Preemptive Multitasking (Preemption)3) Unreliable Networking (Datagrams)4) Filesystems5) Reliable Networking (Streams) 6) Routing (Path vector protocols)Design DocumentAt least a week before project due date, you should meet with course staff, and show them a “design document.”1-2 pagesDescribe design choices, data structures, etc.This is for your benefit, not ours.Design doc, etcInclude revised design doc with final submission. Name it Design.pdf or Design.txt, put it in project folder.If you made significant change since original design, explain why.Also give test strategy...Test strategyGive us a short description (1 paragraph) of how you tested your project, and why we should believe it works.No credit for “I ran the given test progs.”Most systems bugs are hard to find; do stress/endurance tests. Lots of data, long running.TestingInclude your test programs with your submission. Describe them (succinctly) in final design doc/test strategyShould be well thought out; need not be long or time-consuming to write.Grading projectsGrade made up of several parts: test results, code review, design document, test strategy.5% for test strategy, 10% for designRest is a mix of code review and testingRandom TidbitsClass uses CMS.http://cms.csuglab.cornell.edu/2 Class formats (on alternating weeks)Project assigned Project questions (You grill me)Grading20% per lab OR 12%/16%/20%/24%/28%C for Java ProgrammersAri Rabkinbased on lecture slides by Tom Roeder and Oliver KennedyWhy use C?Prettier than assembly, but close match“What you see is what you get”Nothing happens behind your backGrants low-level access to hardwareYou probably know most of it alreadyJava inherited a lot of C’s syntaxPrimitivesInteger Types: int, short, longshort(2 bytes) <= int(2/4) <= long(4/8)Floating Point Types: float, doublefloat(4?) <= double(8?)Character Type: char [signed or unsigned]String = character array (ends with ‘\0’)You manage storage!Control FlowMostly same as JavaExcept that there’s no boolean type.Loop condition is true if integer expression is nonzeroNo exception handling; functions return an error code instead. Be sure to check return valuesControl Flowif( ... ) { ... } else { ... }while( ... ) { ... }for( ... ; ... ; ... ) { ... }Functionsint myFunc(int myVar) { return myVar; }myVar = myFunc(4);Programs start at int main()The Enum/Typedefenum maps text in the code to an integerenum foo { bar, baz, bat };enum foo myVar = bar;enum color { blue = 7, green = 137}; typedef creates a new name for a typetypedef int foo;foo myVar = 3;The StructStructures are like mini-classesNo methods, no inheritance, just variablesstruct foo { int bar; int baz; };struct foo myVar;myVar.bar = 2typedef struct foo {int bar;} baz;baz myVar;The UnionSyntax is like structs, but only one of the members is defined at a time; member storage overlaps.struct foo { int type; union {int bar; float baz;} };Typically use unions inside structscan refer to either bar or baz, but not both at same time. Use type to find out.ArraysArrays work like they do in java... if you know how big the array will be in advance...and no .length variableBe careful with array lengthsStatic Array Sizes: int myArray[20]Dynamic Array sizes: see mallocPointers&var yields the address of variable var* dereferences or declares a pointerint *myPointer = &myIntVar;*myPointer++;myPointer = (int *)malloc(sizeof(int))free(myPointer)Pointers (continued)You must call free() on each pointer you get from malloc after you’re done!You can allocate arrays with malloc()malloc(sizeof(struct foo) * n)These work like normal arrays.Example: MemoryCJavaExample: Pointer UsageSpecial PointersAnonymous pointersvoid *Analogous to Java’s Object; weak typeFunction pointersint call_me(float a) { return (int)a; }int (*fp)(float) = &call_me;(*fp)(3.0); ..... or...... fp(3.0) ;Parameter PassingConsider: b = 3; foo(b); printf(“%d”, b);void foo(int a) { a += 2; } // outputs 3void foo(int *a) { (*a) += 2; } //outputs 5In Java Objects/Arrays behave like case 2In C Pointers/Arrays behave like case 2Some gotchasDeclare all variables at top of function.Free what you malloc, but only onceBe careful with strings...the library string functions don’t manage storage for you.Some referencesThe comp.lang.c FAQ [http://c-faq.com/]C Traps and Pitfalls, by Andrew KoenigThe C Programming Language, by Kernighan and Ritchie (slightly dated)Many other books...Careful...No garbage collection, free what you takeDon’t free things that didn’t get mallocedArrays aren’t bounds checked (and no .length)Variables are initially undefined. (Set pointers to NULL, ints to 0 or whatever)Check for NULL pointers before each use!VC2005 is pretty smart. Listen to it.The Preprocessor#define FOO 42#define foo(a,b) (a+b)#include “myheader.h”#ifdef / #else / #endif#ifdef foo means that if foo is not #defined, everything between that and #else or #endif will be removed by the preprocessorExample: PreprocessorWhy don’t more people use C?Explicit memory management is a painLeaks, Accessing freed memory...Language features dependent on platformSize of primitives, Library availabilityLimited typecheckingPointers can be error-proneAssignment 1First part: Queues Ari RabkinPart 1: A QueueObjectivesImplement a queue with prependShould support Append/Prepend in O(1)Linked Lists are ideal for thisThe queue need not be threadsafe...... but the rest of the project needs to be aware of this.Part 1: A QueueFill in the blanks: queue.c/queue.hDefine one or more structures in queue.cThe world sees a queue_tJust an anonymous pointerUse coercion to operate on queue_t(struct myqueue *)q->lastMemory leaksC has no garbage collector.Won’t reuse memory unless you say free.Program will use too much memory and crash if you don’t.Run a stress test, use Windows task manager to make sure memory usage is bounded.More next week...Next week, I’ll tell you about the rest


View Full Document

CORNELL CS 414 - Operating Systems Practicum

Documents in this Course
Security

Security

49 pages

Processes

Processes

24 pages

Deadlocks

Deadlocks

57 pages

Threads

Threads

5 pages

Threads

Threads

29 pages

Deadlocks

Deadlocks

36 pages

Load more
Download Operating Systems Practicum
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Operating Systems Practicum and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Operating Systems Practicum 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?