Operating Systems - Prof. Omar Mansour
New York University
Tandon School of Engineering
Department of Computer Science and Engineering
Introduction to Operating Systems
Spring 2025
Assignment 6
(10 points)
1) (8 points) Repeat assignment 5B, except that you shall now use a TCP/IP socket for communicating between
the processes instead of a pipe.
Use the following socket functions in their default mode. You may use the man command in your Linux
virtual machine for information about the parameters:
CLIENT SERVER
socket() – opens a socket (similar to pipe() ) socket()
connect() – connects to a server bind() – assigns a particular port number to the server
listen() – listens to connection requests from clients
accept() – accepts a connection from client
read() – reads a buffer from the socket, just as in file
or pipe reading
write() – writes a buffer to the socket, just as in file or
pipe writing
close() – closes the socket close()
You shall use sockets of (domain, type, protocol) = (AF_INET , SOCK_STREAM, 0) and assign the parent
(consumer) as the server and the child (producer) as the client.
Insert an initial random wait (1 to 5 seconds) at the server process (but not the client) prior to it starting to
listen and accept connections.
The client may thus fail to connect if it tries to do so before the server has started to listen (which is after the
random wait). As such, you should insert a loop in the client that repeatedly attempts to connect, waiting 100
ms between attempts, till it succeeds, eventually.
2) 2 points): Answer the following for part 2:
a. Which of the calls above are blocking and which are not?
b. Is this a form of direct communications or indirect communications?
c. What is the failure flag returned from connect() that indicates the server is not ready?
d. How would you change your program to communicate between processes in different machines?
What to submit to gradescope:
Please submit the following files individually:
1) Source file(s) with appropriate comments.
Operating Systems - Prof. Omar Mansour
The naming should be similar to “lab#_$.c” (# is replaced with the assignment number and $ with the
question number within the assignment, e.g. lab4_b.c, for lab 4, question b OR lab5_1a for lab 5, question
1a).
2) A single pdf file (for images + report/answers to questions), named “lab#.pdf” (# is replaced by the
assignment number), containing:
• Screen shot(s) of your terminal window showing the current directory, the command used to
compile your program, the command used to run your program and the output of your program.
3) Your Makefile, if any. This is applicable only to kernel modules.
RULES:
• You shall use kernel version 4.x.x or above. You shall not use kernel version 3.x.x.
• You may consult with other students about GENERAL concepts or methods but copying code (or code
fragments) or algorithms is NOT ALLOWED and is considered cheating (whether copied form other
students, the internet or any other source).
• If you are having trouble, please ask your teaching assistant for help.
• You must submit your assignment prior to the deadline.