CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 2 Questions (document version 1.0)

Similar documents
CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Midterm Exam Questions (document version 1.1)

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 1 Questions (document version 1.1)

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Final Exam Questions (document version 1.1) WITH SELECTED SOLUTIONS

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms

CS321: Computer Networks Socket Programming

ECE 435 Network Engineering Lecture 2

CS321: Computer Networks Introduction to Application Layer

Linux Programming

ECE 435 Network Engineering Lecture 2

Socket Programming for TCP and UDP

Lab 0. Yvan Petillot. Networks - Lab 0 1

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

Oral. Total. Dated Sign (2) (5) (3) (2)

IPv4 and ipv6 INTEROPERABILITY

CS4514 (C04) HELP Session 1 Introduction to Network Programming (v1.3)

CSCI4430 Data Communication and Computer Networks. Pthread Programming. ZHANG, Mi Jan. 26, 2017

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid.

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

CS 471 Operating Systems. Spring 2016 Midterm Exam Time 2 & 1/2 hours. Open Book & Notes

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.0) Network Programming using C

CS 3305 Intro to Threads. Lecture 6

CSci 4061 Introduction to Operating Systems. (Threads-POSIX)

The User Datagram Protocol

CS4514 B08 HELP Session 1

Elementary TCP Sockets

UDP CONNECT TO A SERVER

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

// Embedded Systems // BeagleBoard-XM. // Author : Jose Goncalves //

CS 3516: Computer Networks

518 Lecture Notes Week 12

This exam paper contains 8 questions (12 pages) Total 100 points. Please put your official name and NOT your assumed name. First Name: Last Name:

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Ports under 1024 are often considered special, and usually require special OS privileges to use.

SOCKETS. COMP750 Distributed Systems

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff

// socket for establishing connections

CMPSC 311- Introduction to Systems Programming Module: Concurrency

The course that gives CMU its Zip! Concurrency I: Threads April 10, 2001

CMPSC 311- Introduction to Systems Programming Module: Concurrency

CSC209 Review. Yeah! We made it!

CSCE 463/612 Networks and Distributed Processing Spring 2017

CMPSC 311- Introduction to Systems Programming Module: Concurrency

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

CS 450 Introduction to Networking Spring 2014 Homework Assignment 1 File Transfer and Data Bandwidth Analysis Tool

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

Network Socket Programming - 3 BUPT/QMUL

Concurrent Servers. Overview. In our current assignment we have the following changes:

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

CSE 333 SECTION 9. Threads

CS 345 Operating Systems. Tutorial 2: Treasure Room Simulation Threads, Shared Memory, Synchronization

Concurrent Programming

Tutorial on Socket Programming

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

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

Ken French HELP Session 1 CS4514

CS444 1/28/05. Lab 03

CPSC 213. Introduction to Computer Systems. Inter-Process Communication. Unit 2f

Chapter 6. The Transport Layer. Transport Layer 3-1

Network Socket Programming - 3 BUPT/QMUL

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Unix Network Programming

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

STUDY OF SOCKET PROGRAMMING

Socket Programming(2/2)

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

First Midterm Exam September 28, 2017 CS162 Operating Systems

A. Basic Function Calls for Network Communications

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

CS 220: Introduction to Parallel Computing. Condition Variables. Lecture 24

Group-A Assignment No. 6

Lecture 4. Threads vs. Processes. fork() Threads. Pthreads. Threads in C. Thread Programming January 21, 2005

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

System Programming. Sockets: examples

Processes and Threads

Introduction to Threads

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

Concurrent Server Design Multiple- vs. Single-Thread

How to write a Measurement Telnet Server

CSE 421/521 - Operating Systems Fall 2011 Recitations. Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar. Presented by...

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.1) Sockets and Server Programming using C

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

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.

Thread and Synchronization

ANSI/IEEE POSIX Standard Thread management

More Network Programming

Assignment #2. Problem 2.1: airplane synchronization

What s an API? Do we need standardization?

pthreads Announcement Reminder: SMP1 due today Reminder: Please keep up with the reading assignments (see class webpage)

1.2 The first Internet (i.e., one of the first packet switched networks) was referred to as the ARPANET.

How to write a Measurement Telnet Server

Lecture 19: Shared Memory & Synchronization

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

CSE 333 SECTION 6. Networking and sockets

EECS122 Communications Networks Socket Programming. Jörn Altmann

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Network Software Implementations

Transcription:

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 2 Questions (document version 1.0) Overview Exam 2 will be in class on Thursday, April 13, 2017 from 10:00-11:45AM (please arrive early and sit with empty seats next to you on both sides). Exam 2 will be 105 minutes; therefore, if you have 50% additional time, you will have 160 minutes; if you have 100% additional time, you will have 210 minutes. Exam 2 will count as 10% of your final course grade. You may bring two double-sided (or four single-sided) 8.5 x11 crib sheets containing anything you would like; crib sheets will not be collected. Exam 2 will be handed back and reviewed on Monday, April 24, 2017. Grade grievances must be made no later than Monday, May 1, 2017 by handing your exam back to Professor Goldschmidt (after class or during office hours). Exam 2 will cover everything we have done since Exam 1, except for Java, though note that knowledge of some material (e.g., system calls in C) is required from earlier in the semester. Therefore, it is a good idea to review the sample Exam 1 questions and Exam 1.

Exam 2 Review Questions 1. What do the following system calls do? What are their input arguments and return values? pthread_create() pthread_detach() pthread_self() pthread_join() pthread_exit() 2. What are the system calls for working with shared memory segments in multi-process systems? What does each system call do? What are their input arguments and return values? 3. In a multi-threaded program, what kinds of synchronization errors can occur? How can these situations be avoided? 4. What is a critical section? 5. For semaphores, what are the definitions of the P() and V() operations? Further, what is a binary semaphore and what is a counting semaphore? How are each used to avoid synchronization problems? 6. What is the OSI reference model? 7. What is data marshalling? Why is it important? 8. What are the key differences between TCP and UDP? 9. Describe the addressing scheme used in IP. 10. What do the following system calls do? What are their input arguments and return values? socket() bind() listen() connect() gethostbyname() recv() send() recvfrom() sendto() 2

Sample Exam 2 Questions 1. Answer the questions below. (a) Given the following C program, what is the exact terminal output? If multiple outputs are possible, use a diagram to succinctly show all possibilities. Assume that all system calls complete successfully. Further, assume that the main thread ID is 1111, with any child threads numbered sequentially 8888, 8889, 8890, etc. void * omg( void * arg ) int * x = (int *)arg; int rc = pthread_detach( pthread_self() ); printf( "%u lucky %d %d\n", (unsigned int)pthread_self(), *x, rc ); pthread_t tid; int x = 7; int rc = pthread_create( &tid, NULL, omg, &x ); printf( "%u %d\n", (unsigned int)pthread_self(), rc ); rc = pthread_create( &tid, NULL, omg, &x ); usleep( 1000 ); /* wait for child threads to end... */ (b) What is the most likely terminal output of the code above if the sleep() call is commented out? Again assume that all system calls complete successfully. If multiple outputs are possible, do not show all possibilities. 3

2. Answer the questions below. (a) Given the following C program, what is the exact terminal output? If multiple outputs are possible, use a diagram to succinctly show all possibilities. Assume that all system calls complete successfully. Further, assume that the main thread ID is 1111, with any child threads numbered sequentially 8888, 8889, 8890, etc. int x = 12; void * lmao( void * arg ) int q = 4; int * z = (int *)arg; q -= 2; printf( "%u %d %d\n", (unsigned int)pthread_self(), *z, q ); *z *= 2; pthread_t tid1, tid2; pthread_create( &tid1, NULL, lmao, &x ); pthread_create( &tid2, NULL, lmao, &x ); pthread_join( tid1, NULL ); pthread_join( tid2, NULL ); (b) What is the exact terminal output of the code above if the two pthread_join() calls are removed? Again assume that all system calls complete successfully. If multiple outputs are possible, use a diagram to succinctly show all possibilities. 4

3. Expand the code from Question 2 (shown below) by implementing a mutex to ensure no synchronization problems occur with shared variable x. int x = 12; void * lmao( void * arg ) int q = 4; int * z = (int *)arg; q -= 2; printf( "%u %d %d\n", (unsigned int)pthread_self(), *z, q ); *z *= 2; pthread_t tid1, tid2; pthread_create( &tid1, NULL, lmao, &x ); pthread_create( &tid2, NULL, lmao, &x ); pthread_join( tid1, NULL ); pthread_join( tid2, NULL ); 5

4. Answer the questions below. (a) Given the following C program, what is the exact terminal output? If multiple outputs are possible, use a diagram to succinctly show all possibilities. Assume that all system calls complete successfully. Further, assume that the main thread ID is 1111, with any child threads numbered sequentially 8888, 8889, 8890, etc. (b) What is the exact contents of the EE.txt file? #define SNAPCHAT 2 void * rofl( void * arg ) int * f = (int *)arg; printf( "%uaa%d\n", (unsigned int)pthread_self(), *f ); fprintf( stderr, "%ubb\n", (unsigned int)pthread_self() ); close( SNAPCHAT ); printf( "%ucc\n", (unsigned int)pthread_self() ); fprintf( stderr, "%udd\n", (unsigned int)pthread_self() ); int fd = open( "EE.txt", O_WRONLY O_CREAT O_TRUNC, 0660 ); printf( "%uff\n", (unsigned int)pthread_self() ); fprintf( stderr, "%ugg%d\n", (unsigned int)pthread_self(), fd ); pthread_t tid1, tid2; int rc = pthread_create( &tid1, NULL, rofl, &fd ); rc = pthread_create( &tid2, NULL, rofl, &rc ); pthread_join( tid1, NULL ); pthread_join( tid2, NULL ); printf( "%uhh\n", (unsigned int)pthread_self() ); fprintf( stderr, "%uii\n", (unsigned int)pthread_self() ); fflush( NULL ); close( fd ); (c) Repeat parts (a) and (b) above if SNAPCHAT is set to 1 instead of 2. 6

5. Answer the questions below. (a) Given the following C program, what is the exact terminal output when a client connects and sends the following strings? Assume that all system calls complete successfully. "ABCDEFGH"; "ABCDEFGH\n"; "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; "ABCDEFGHIJ\n" #define BUFFER_SIZE 10 char buffer[ BUFFER_SIZE + 1 ]; int sd = socket( PF_INET, SOCK_STREAM, 0 ); struct sockaddr_in server; server.sin_family = PF_INET; server.sin_addr.s_addr = INADDR_ANY; unsigned short port = 8123; server.sin_port = htons( port ); bind( sd, (struct sockaddr *)&server, sizeof( server ) ); listen( sd, 5 ); printf( "SERVER: Listener bound to port %d\n", port ); struct sockaddr_in client; int fromlen = sizeof( client ); int clients = 10; while ( clients > 0 ) printf( "SERVER: Blocked on accept()\n" ); int newsd = accept( sd, (struct sockaddr *)&client, (socklen_t *)&fromlen ); while ( 1 ) printf( "SERVER: Blocked on recv()\n" ); int n = recv( newsd, buffer, BUFFER_SIZE, 0 ); buffer[n] = '\0'; /* assume text data */ printf( "SERVER: Rcvd [%s]\n", buffer ); close( newsd ); clients--; printf( "SERVER: Exiting\n" ); (b) What happens when the client socket closes? Add to the code above to make sure the server does not crash or enter into an infinite loop. 7