PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Similar documents
PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

UNIVERSITY OF TORONTO SCARBOROUGH Computer and Mathematical Sciences. APRIL 2016 EXAMINATIONS CSCB09H3S Software Tools & Systems Programming

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

File Descriptors and Piping

CSC209 Review. Yeah! We made it!

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Workshop on Inter Process Communication Solutions

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209H Lecture 7. Dan Zingaro. February 25, 2015

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE551 Midterm Version 2

Faculty of Applied Science and Engineering, University of Toronto CSC181: Introduction to Computer Programming, Fall 2000

CSC209H1S Day Midterm Solutions Winter 2010

ECE551 Midterm Version 1

Student Number: Instructor: Reid Section: L0201 (12:10-1:00pm)

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Week 13. Final exam review

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

Pebbles Kernel Specification September 26, 2004

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes

CSE 333 SECTION 3. POSIX I/O Functions

CSE 410: Systems Programming

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

Socket programming in C

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Section 3: File I/O, JSON, Generics. Meghan Cowan

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

MARKS: Q1 /20 /15 /15 /15 / 5 /30 TOTAL: /100

CPS 310 first midterm exam, 2/26/2014

CSE351 Winter 2016, Final Examination March 16, 2016

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

A brief introduction to C programming for Java programmers

BLM2031 Structured Programming. Zeyneb KURT

ECE551 Midterm Version 1

The course that gives CMU its Zip! I/O Nov 15, 2001

CSE 333 Midterm Exam 2/12/16. Name UW ID#

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Question 1. Part (a) Part (b) Part (c) Part (d) Part (e) Part (f) APRIL 2012 Final Examination Solutions CSC 209H1S

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 6

In class we examined the need for concurrent execution paths like a consumer and a producer to synchronize their access to a shared ring buffer.

CS321: Computer Networks Socket Programming

Do not start the test until instructed to do so!

What Is Operating System? Operating Systems, System Calls, and Buffered I/O. Academic Computers in 1983 and Operating System

Project 2: Shell with History1

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CSC231 C Tutorial Fall 2018 Introduction to C

CSE 333 Midterm Exam 2/14/14

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

ECE 551D Spring 2018 Midterm Exam

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Memory Allocation in C C Programming and Software Tools. N.C. State Department of Computer Science

CS 470 Operating Systems Spring 2013 Shell Project

CSE 333 SECTION 3. POSIX I/O Functions

Student Number: Computer Science 211b Final Examination. 28 April hours

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

CS 61C: Great Ideas in Computer Architecture Introduction to C

COMP1917: 09 Arrays and Strings

SOFTWARE Ph.D. Qualifying Exam Fall 2017

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

String constants. /* Demo: string constant */ #include <stdio.h> int main() {

Concurrent Servers Dec 2, 2009"

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data;

CSE 333 Midterm Exam July 24, Name UW ID#

Processes. Processes (cont d)

CS Operating system Spring Final -- May 8, You have 120 min. Good Luck!

ESC101N: Fundamentals of Computing End-sem st semester

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Lab 4. Out: Friday, February 25th, 2005

Application Programming Interfaces

ECE 435 Network Engineering Lecture 2

Transcription:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST 2011 EXAMINATIONS CSC 209H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: one two-sided 8.5x11 sheet. Student Number: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have received the signal to start. (In the meantime, please fill out the identification section above, and read the instructions below carefully.) Marking Guide This examination consists of 10 questions on 16 pages (including this one). Instructions: Check to make sure that you have all 16 pages. Read the entire exam before you start. Not all questions are of equal value, so budget your time accordingly. You do not need to add import lines or do error checking If you use any space for rough work, indicate clearly what you want marked. # 1: /12 # 2: / 6 # 3: / 5 # 4: / 5 # 5: / 6 # 6: /10 # 7: / 7 # 8: / 7 # 9: /12 # 10: / 1 Good Luck! TOTAL: /71 Page 1 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 1. Part (a) [12 marks] Write a single Bourne shell command that runs program foo with a commandline argument of bar, and sends the output to file outf. Part (b) The following shell commands retrieve the number of lines in file restaurant list that contain the word Toronto. However, all quoting has been removed. Add the proper types of quotes where ever they are required. a=cat restaurant list b=echo $a grep -c Toronto Part (c) int arraysum (int a[]) {... // don t write code } Explain why sizeof(a) cannot be used to obtain the number of elements in the array. Page 2 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Part (d) How many times does the original parent process output hello\n? int main(void) { printf("hello\n"); fork(); fork(); printf("hello\n"); return 0; } Part (e) Briefly explain what happens between the time I hit ctrl-c and the time the process terminates. Part (f) When a program is executing a handler for signal type s, no other signal of type s can interrupt the handler. Yet, if a signal of type s is received while executing the signal handler, the signal of type s will be delivered once the handler completes. Is signal type s being blocked or ignored in the handler? Explain. Page 3 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 2. [6 marks] Consider text files where each line consists of zero or more integers. Here is one sample file: 4 8 1 6 5 4 3 2 1 Write a Bourne shell program that takes zero or more such files on its commandline, and outputs the total value of adding up all of the integers from all of the lines of all of the files. Your program should output only the total (i.e. a single integer) and nothing else. Page 4 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Question 3. [5 marks] Consider the following C code. int i = 1; int *p[5]; //b int **pp; p[0] = &i; pp = &p[0]; //c printf("%d\n", **pp); //d Part (a) [1 mark] What is the type of each element in p? Part (b) [1 mark] Write the equivalent of the //b line using malloc instead of an array. Part (c) [1 mark] Write the equivalent of the //c line without using the array [] notation. Part (d) What is the output of the //d line? If the line contains an error or tries to access a variable that is not initialized, describe the problem rather than giving the output. Page 5 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 4. [5 marks] Here is part of the man page for a C function called strspn. SYNOPSIS #include <string.h> size_t strspn(const char *s, const char *accept); DESCRIPTION The strspn() function calculates the length of the initial segment of s which consists entirely of characters in accept. RETURN VALUE The strspn() function returns the number of characters in the initial segment of s which consist only of characters from accept. For example, strspn ("hello", "haeiou") returns 2: the h and e are in accept, but the l is not. Write an implementation of strspn. You may use strlen, but do not use any other string functions. size_t mystrspn(const char *s, const char *accept) { Page 6 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Question 5. [6 marks] Write a C function that reads an entire line, including the newline, from a file descriptor fd. fd is guaranteed to contain a line when readline is called. You should read only up to and including the newline character, and no further. Assume that buf is large enough to contain any possible line. You must use read (not fread or fgets or anything else) to read from the file descriptor. The function should return -1 on error and 0 on success. If the function succeeds, buf should be a valid string (i.e. with a \0 at the end). int readline(int fd, char *buf) { Page 7 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 6. [10 marks] Consider the following typedef, which creates a new type called Pair. typedef struct node { int x, y; struct node *next; } Pair; Part (a) The code below creates several nodes and connects some of them through next pointers. Draw the linked list that starts at a. Don t draw anything that is not reachable from a. Pair *a = malloc(sizeof(pair)); Pair *b = malloc(sizeof(pair)); Pair *c = malloc(sizeof(pair)); a->x = 1; a->y = 2; b->x = 3; b->y = 4; c->x = 5; c->y = 6; a->next = b; a->next->next = c; b->next = NULL; Page 8 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Part (b) [3 marks] pl is a linked list of Pairs. Write a function isxval that returns a true value if val exists as any x- component of a Pair in pl, and a false value otherwise. int isxval (const Pair *pl, int val) { Part (c) [5 marks] Write a function copyreverse that creates a new linked list consisting of all nodes in old, but in reverse order. The new list and the old should be independent, so that modifying an x or y in one list does not modify the other list. The function returns the head of the new list using the second parameter of the function (not through a return statement!). void copyreverse (Pair *old, Pair **new) { Page 9 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 7. [7 marks] Part (a) [4 marks] When I run the following code, one of two things happens: Scenario I: There is no output at all, or Scenario II: The child prints Wrote in pipe\n int main(void) { int child; int fd[2]; if (pipe(fd) == -1) { perror ("pipe"); exit (1); } if ((child = fork()) == -1) { perror ("fork"); exit (1); } else if (child == 0) { char *s = "Lake Hylia\n"; close (fd[0]); write (fd[1], s, strlen(s)); printf ("Wrote in pipe\n"); } else { close (fd[1]); /*Code for part b goes here*/ } close (fd[0]); exit (0); } return 0; The reason that there are two scenarios has to do with the order that things happen after the fork. Carefully describe what happens after the fork to cause each of these two scenarios. Scenario I: Scenario II: Part (b) [3 marks] Fill in the missing parent code so that it reads the string from the pipe and prints it on standard output. Do not hard-code the number 11. Page 10 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Question 8. [7 marks] Write a function that reads from fromfd and copies what it reads to tofd. fromfd is a file descriptor open for reading and tofd is a file descriptor open for writing. The function continues until one of two things happens: There is an end-of-file on fromfd, or There is read action (i.e. any bytes to read, or end-of-file) on quitfd. quitfd is a file descriptor open for reading. You must use select in your solution: you are not allowed to block on one file descriptor when there could be action on the other. void fdecho (int fromfd, int tofd, int quitfd) { Page 11 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 9. [12 marks] Part (a) Explain what is meant by the Network Newline Convention. Why is such a convention necessary? Part (b) A client would like to write an integer to a socket. Which function, htons or ntohs, should first be called on that integer? Explain why calling that function is necessary. Page 12 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y Part (c) [8 marks] In this part, you will write the body of a small server. Assume that all setup has been done and that you have a global socket file descriptor listenfd that is in the listening state. Your server will accept one client at a time. When each client c connects: Send c all of the text from the previous client (if c is the first client, nothing gets sent to them), and then Read from c until c disconnects or your buffer is full. disconnect the client. If your buffer fills, empty the buffer and For example, when the first client connects, you send them nothing and read from them until they drop or your buffer gets full. Let s say that you read the text rupee from them. Then, later, when the second client connects, you send them rupee and read from them until they disconnect. If you read the text lanmolas from them, you send lanmolas to client 3... and so on. If one of the clients sends you too much text (so that your buffer is overflowed), the client after them does not get any text from you. //Here is the syntax for accept //accept(listenfd, (struct sockaddr *)&r, &socklen) int listenfd; int main(void) { struct sockaddr_in r; socklen_t socklen = sizeof (r); setup(); //socket(), bind(), listen() done; listenfd is listening //Declare all variables and write code Page 13 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 Question 10. [1 mark] Sometimes, we learn important things besides course content. In this course, you learned (circle one): You are still convinced that it is me singing love.wav You are rocking cartoon.wav on your MP3 player You are going to play Zelda 3 for the rest of the summer and then talk to me about its epicness You think that malloc should be a four-letter word Tiles are supposed to do that You never want to see another glibc: corruption or double free error again You suddenly love Western Meadowlarks It s been a privilege. Have a great summer! [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark.] Page 14 of 16 cont d...

AUGUST 2011 Final Exam CSC 209H1Y [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark.] Page 15 of 16 cont d...

CSC 209H1Y Final Exam AUGUST 2011 [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark.] Page 16 of 16 End of Examination