CS252 Final Review

CS252 Final Review - CS252 Final Review Please aswer this...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS252 Final Review Please aswer this final review and return it during the final exam. If you write down the solution in HTML and turn it in before 1:00pm the day before the final exam, you will get up to 4 extra points in the final exam. The submitted solutions will be posted. 1. Complete the procedure runCommand ( command, outputBuffer, bufferSize) that executes a command in a different process and stores its output in outputBuffer. command is the name of the program with no arguments. See how main uses runCommand (). runCommand will return 0 on success or -1 otherwise. Hint: Use a pipe to communicate the parent and the child process running runCommand(). Have the parent read from the pipe and write into the outputBuffer. int runCommand( char * command, char * outputBuffer, int maxBufferSize) { } int main() { // The output of "ls" will be stored in buffer char buffer[ 1024 ]; if ( runCommand( "ls", buffer, 1024 ) < 0 ) { perror("runCommand" ); exit( -1 ); }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
printf( "ls: %s\n", buffer ); exit( 0 ); } 2. Add the necessary code to the insert() and removeFirst() functions to make them synchronized. removeFirst() will have to wait if the list is empty. insert() will have to wait if there are already 20 elements in the list. Use semaphores . Add also the variables you need. struct List { int val; int next; }; struct List * head = NULL; // More variables main() { // DO any initializations here } void insert( int val ) { List tmp = new List; tmp->val = val; tmp->next = head; head = tmp; } Struct List * removeFirst() { List tmp = head; head = tmp->next;
Background image of page 2
return tmp; } 3. From lab3, assuming you have a procedure void dispatchHTTP( int slaveSocket)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

CS252 Final Review - CS252 Final Review Please aswer this...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online