IPC for Data Passing Flashcards
IPC
Inter-Process Communication
Pipe
- IPC technique for passing information to another process
- uses byte-stream
- only for use between child and parent
- one reader and one writer
- purely in-memory
- pipe is deleted after all fds closed
Byte-Stream
Message that has no notion of “boundaries”. No space division between messages
pipe()
int pipe( int fd[2] )
- creates a new pipe and returns two file descriptors
- f[0] is read end
- f[1] is write end
fork()
Child inherits fd[0] and fd[1]
close()
Closes unused file descriptors
How do pipes work under the hood?
- in-memory file system,PIPEFS, in the kernel memory address space
- pipefs mounted at system initialization
- pipe corresponds to a file created in pipefs
- pipe() creates pipe and returns two file descriptors (one read and one write)
FIFO
Named Pipe.
- uses byte-stream
- not limited to be used between parent and child process
- multiple writers and one reader
- file created in hard disk, but I/O through kernel memory
- not deleted after closing all fds
Message Queues
Like named pipe but supports boundaries and message types/priorities
Unix Domain Socket
- like a pipe combined with a message queue
- named using path name
- supports byte-stream and datagrams
- bidirectional
Shared Memory
Region of physical memory that is mapped to two (or more) processes, both can edit and view same data