April 23, 2019
For today:
1) Read Head First C Chapter 11
2) Start Homework 11
3) Submit a project update
Today:
1) Interprocess communication
2) Sockets
3) Exercise 11 / Project time
For next time:
1) Read Think OS Chapter 11 and do the reading quiz
2) Finish Homework 11
3) Work on your project
Threads in the same process share the heap and static segments, so they usually communicate through shared data structures: simple things like a global flag, medium things like an "object" that contains shared state, more formal things like a work queue.
Processes don't share much, so they communicate with each other by:
reading and writing files (and using file locks)
sending signals
pipes
UNIX named pipes
shared memory
sockets
This page has a good overview of IPC and details of shared memory:
http://www.ibm.com/developerworks/aix/library/au-spunix_sharedmemory/
Sockets are the only mechanism on this list that permits IPC between processes on different machines.
(Although the idea of "same machine" has become increasingly complicated: same CPU? same kernel? same virtual machine? same physical memory? same file system?)
Named sockets are not widely used and are not always provided.
Sockets
Plain old sockets are widely used for both local and remote communication.
They provide a stream of bytes abstraction similar to files and pipes.
Sockets support lots of protocols, but the most common are:
1) Unix domain socket: used for local communication, tuned for reliable communication
2) UDP: Like sending postcards in the mail. To Bali.
3) TCP: Connection-based, reliable, in-order delivery using acknowledgements and retransmission. Also flow control and congestion control!
Gee, Mr. Wizard, that's a lot of functionality in one protocol.
Yes, kids. It is.
Servers run
socket()
setsockopt()
bind()
listen()
accept()
send() and recv() or fdopen()
close()
Clients run
socket()
connect()
send() and recv() or fdopen()
close()
Draw a thread diagram that shows this sequence of events for advice_server.c
How would the diagram look different if the server spawns a process/thread to handle the request?
One last thing: the select system call.
If you find yourself writing anything server-like, you will eventually come face to face with the Cthulhu of UNIX.