DOC PREVIEW
U of I CS 241 - Midterm Review

This preview shows page 1-2-3-4-5-6-44-45-46-47-48-49-50-89-90-91-92-93-94 out of 94 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 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 94 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 94 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Midterm ReviewC BasicsThe “&” Operator: Reads “Address of”PointersThe “*” Operator Reads “Variable pointed to by”ArraysStrings (Null-terminated Arrays of Char)String OperationsMath: Increment and Decrement OperatorsMath: Increment and Decrement Operators on PointersSystem CallsExamples of System CallsSystem Calls for I/OI/O Library CallsProcessesProcess IdentificationCreating a Process – fork()Chain and FanProcess Terminationwait() FunctionZombie RemovalOrphansexec() FunctionThreadsThreads: Lightweight ProcessesTrade-offs?Hybrid Implementations (Solaris)SynchronizationCritical Region (Critical Section)Critical Region RequirementsCritical Region RequirementsSlide 32Lock VariablesTurn-based Mutual Exclusion with Strict AlternationOther Flag Mutual ExclusionTwo Flag Mutual ExclusionTwo Flag and Turn Mutual ExclusionSemaphoresExampleMutexPOSIX Mutex-related FunctionsSchedulingPreemptive vs. Non-preemptive schedulingScheduling ObjectivesPerformance CriteriaSimple Processor Scheduling AlgorithmsSignalsExamples of POSIX Required SignalsSlide 49Command Line Generates SignalsCommand Line Generates SignalsTimers Generate SIGALRM SignalsExamples: Programming SignalsProgramming SignalsSignal MasksSignal SetsSIGPROCMASKExample: Add SIGINT to Set of Blocked SignalsCatching and Ignoring Signals - SIGACTIONWaiting for SignalssigsuspendUse sigwaitTimersTiming a function (Example 1)TimePOSIX XSIRealtime clocksSleep Functions (Example 6)NanosleepPOSIX:XSI Interval TimersProducer-ConsumerProducer-Consumer ProblemDining PhilosophersDeadlockSlide 75Resource Allocation GraphStrategiesThe Default SolutionDeadlock PreventionDeadlock AvoidanceIs Allocation (1 0 2) to P1 Safe?Run Safety TestAllocate to P1, ThenRelease - P1 FinishesRelease - P3 FinishesRelease - P4 FinishesRelease - P2 FinishesSo P1 Allocation (1 0 2) Is SafeIs allocation (0 2 0) to P0 Safe?Slide 90So Unsafe State- Do Not EnterP0 Suspended Pending RequestDeadlock DetectionRecovery From DeadlockCopyright ©: Nahrstedt, Angrave, Abdelzaher 1Midterm ReviewTarek AbdelzaherCopyright ©: Nahrstedt, Angrave, Abdelzaher2C BasicsQuestions of the form:Is this code snippet correct?Find all the 5 bugs in the given code snippetWhat is the value of X, Y, Z at the end of the given code snippetetc.Copyright ©: Nahrstedt, Angrave, Abdelzaher310,00010,00210,00810,01010,012…The “&” Operator:Reads “Address of”Value1Value2Value3Value4Value5xyzpdNameValue&yCopyright ©: Nahrstedt, Angrave, Abdelzaher410,00010,00210,00810,01010,012…PointersValue1Value2Value310,002Value5xyzpdNameValueA pointer is a variable whose value is the address of anotherCopyright ©: Nahrstedt, Angrave, Abdelzaher510,00010,00210,00810,01010,012…The “*” OperatorReads “Variable pointed to by”Value1Value2Value310,002Value5xyzpdNameValueA pointer is a variable whose value is the address of another*PCopyright ©: Nahrstedt, Angrave, Abdelzaher6Arraysint p[5]; p[0]p[1]p[2]p[3]p[4]Name of array (is a pointer)pShorthand:*(p+1) is called p[1]*(p+2) is called p[2]etc..Copyright ©: Nahrstedt, Angrave, Abdelzaher7Strings (Null-terminated Arrays of Char)Examplechar s[5];Strings are arrays that contain the string characters followed by a “Null” character to indicate end of string.Do not forget to leave room for the null characters[0]s[1]s[2]s[3]s[4]sCopyright ©: Nahrstedt, Angrave, Abdelzaher8String OperationsstrcpystrlensrtcatstrcmpCopyright ©: Nahrstedt, Angrave, Abdelzaher9Math: Increment and Decrement OperatorsExample 1:int x, y, z, w;y=10; w=2;x=++y;z=--w;Example 2:int x, y;y=10; w=2;x=y++;z=w--;First increment/decrement then assign resultx is11, z is 1First assign then increment/decrementx is 10, z is 2Copyright ©: Nahrstedt, Angrave, Abdelzaher10Math: Increment and Decrement Operators on PointersExample 1:int a[2];int number1, number2, *p;a[0]=1; a[1]=10; a[2]=100; p=a;number1 = *p++;number2 = *p;What will number1 and number2 be at the end?Hint: ++ increments pointer p not variable *pCopyright ©: Nahrstedt, Angrave, Abdelzaher11System CallsfnCall()ProcessCaller and callee are in the sameProcess - Same user - Same “domain of trust”Function CallsysCall()ProcessSystem CallOS- OS is trusted; user is not.- OS has super-privileges; user does not- Must take measures to prevent abuseCopyright ©: Nahrstedt, Angrave, Abdelzaher12Examples of System CallsExample:getuid() //get the user IDfork() //create a child processexec() //executing a programDon’t mix system calls with standard library callsDifferences?Is printf() a system call?Is rand() a system call?Copyright ©: Nahrstedt, Angrave, Abdelzaher13System Calls for I/OThere are 5 basic system calls that Unix provides for file I/Oint open(char *path, int flags [ , int mode ] ); (check man –s 2 open)int close(int fd); int read(int fd, char *buf, int size); int write(int fd, char *buf, int size); off_t lseek(int fd, off_t offset, int whence); They look like regular procedure calls but are differentA system call makes a request to the operating system. A procedure call just jumps to a procedure defined elsewhere in your program. Some library calls may themselves make a system call(e.g. fopen() calls open())Copyright ©: Nahrstedt, Angrave, Abdelzaher14I/O Library CallsEach system call has analogous procedure calls from the standard I/O library:System Call Standard I/O callopen fopenclose fcloseread/write getchar/putchargetc/putcfgetc/fputcfread/fwritegets/putsfgets/fputsscanf/printffscanf/fprintflseek fseekCopyright ©: Nahrstedt, Angrave, Abdelzaher15ProcessesPossible process statesRunning (occupy CPU)BlockedReady (does not occupy CPU)Other states: suspended, terminatedQuestion: in a single processor machine, how many process can be in running state?Copyright ©: Nahrstedt, Angrave, Abdelzaher16Process IdentificationUNIX identifies processes via a unique Process ID Each process also knows its parent process ID since each process is created from a parent process. Root process is the ‘init’ process‘getpid’ and ‘getppid’ – functions to return process ID (PID) and parent process ID (PPID)Example 1#include <stdio.h>#include <unistd.h>int main (void) {printf(“I am process %ld\n”, (long)getpid());printf(“My parent id %ld\n”, (long)getppid());return 0; }Copyright ©: Nahrstedt, Angrave, Abdelzaher17Creating a


View Full Document

U of I CS 241 - Midterm Review

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Midterm Review
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 Midterm Review 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 Midterm Review 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?