| title | Inter-process communication |
|---|
Compile me with:
pandoc --standalone --to=revealjs --output=README.html README.md --slide-level=2
- Mostly OS primitives
- A few programming models
- When to use each?
- Take only 35 mins
::: {.incremental}
- How to launch processes?
fork()- →
clone()A fork in the road
:::
- Explicit == message passing
- Implicit == ? [shared memory]{.fragment}
::: {.incremental}
- Use threads
- Mmapped file
- POSIX shared memory
- Sys V shared memory
:::
- Mmapped file:
open,mmap, ...,munmap,close - Incurs I/O overhead eventually
shm_open,ftruncate,mmap, ...,munmap,close,shm_unlink- /dev/shm
- Real world ex in fsatrace
[What about threads?]{.fragment}
::: {.incremental}
- Both threads and POSIX shm
- Race conditions!
- Synchronization
- Race conditions!
- POSIX shm
- Shm could mmapped to different address!
- Wrong:
*p = target;Right:*p = target - baseaddr;
- Wrong:
- Globally unique keys?
- Pointers may be pointing outside of shm
- Shm could mmapped to different address!
:::
::: {.incremental}
- Pipes
- FIFOs (aka "named pipes")
- Socket (UNIX, TCP, UDP)
- POSIX message queue
- Sys V message queue
- man sysvipc :::
- Pipes:
pipe()andfork()(inherit fds)- Must be "related" procs
- Each proc must close one end!
- Real world ex in benchexec
- FIFOs:
mkfifo(name)- Uses normal POSIX FS
- Real world ex in Zsh
::: {.incremental}
- Sequential (unlike random-access mmap)
- Finite capacity
- Why?
- Backpressure
- Blocking/non-blocking
- Versus file?
:::
mq_open(),mq_send()/mq_recv(),mq_unlink()- Sequential
- Finite capacity
- Blocking/non-blocking
- Server: [
socket(), ]{.fragment} [bind(), ]{.fragmet} [listen(),]{.fragment} [accept(),]{.fragment} [..., ]{.fragment} [close()]{.fragment} - Client: [
socket(),]{.fragment} [connect(),]{.fragment} [...,]{.fragment} [close()]{.fragment} - Address: UNIX domain, IPv4, or IPv6
- Type: Stream, datagram, sequential packet
- Single server, multiple clients
- Directionality? [Bidirectional]{.fragment}
- Capacity? [Infinite]{.fragment}
- Blockingness? [Non-blocking]{.fragment}
::: {.incremental}
- Q: Why do POSIX facilities (
shm_open,mq_open,connect,accept) return file descriptors? - A:
e/poll()andselect()use FDs (non-blocking) - So stay away from SysV facilities!
:::
::: {.incremental}
- Hitting RAM is slow, so cores have caches
- How to know if another core changed something?
- Cache coherence protocol
- Cores actually do exchange messages!
:::
::: {.incremental}
- Which IPCs support inter-node communication?
- You might think, "only sockets"
- But cache coherence protocols make PGAS possible
:::
- OS knows ident of user reading socket (no need for passwd)
- Going to network requires changing address anyway
sudo -u nextcloud psql
- Remote functions
- Remote objects ("sea of objects")
::: {.incremental}
- Erlang
- Go lang
- "don't communicate by sharing memory; share memory by communicating" src
- still racey
:::
::: {.incremental}
- FIFO? TCP socket
- UNIX socket? TCP socket
- POSIX MQ? Kafka on a TCP socket
:::



