IPC Flashcards
Pipe Characteristics
- Uses a buffer in the kernel
- Unidirectional
- Byte Stream
What happens if you try to write to a pipe more bytes than PIPE_BUF can store
it may be non-atomic
What is returned by ‘read’ when the write end is closes by all processes
read() returns 0
Why use a FIFO
Unrelated processes can’t use a pipe
FIFO vs pipe
A FIFO is a ‘named pipe’ similar to a UNIX domain socket
Message Queue vs FIFO
message queues can be used to send structured data i.e. a struct/union instead of a byte stream
File mapping vs. Anonymous mapping
File mapping - maps a file to a memory region, allows us to write to files w/out read/write (memory-mapped file)
Anonymous mapping - another way to allocate memory to a process
Shared vs. Private memory mapping
Shared - create a file/anonymous mapping then fork, parent/child will share the same mapping
Private - each process has a private copy
Private file mapping
Each process gets its own copy in memory of the file, but changes won’t be written to the actual file
Private anonymous mapping
More memory gets allocated to the calling process, fork() copies the memory but each process has a private copy
Shared file mapping
A file is mapped to a process as shared mapping, all changes will be propagated across all files and will be written to the actual file
Shared anonymous mapping
More memory gets allocated to the calling process, memory is shared and changes are propagated across processes
mmap flags for shared memory
MAP_SHARED | MAP_ANONYMOUS
Shared memory
allows sharing memory across unrelated processes