LU5 IPC Flashcards
What does IPC stand for in system programming?
Interprocess Communication
What is the primary purpose of IPC?
To allow two or more processes to exchange information with each other.
Name two types of IPC mechanisms that only support local usage.
Signals & pipes
What happens if the buffer in a pipe is empty?
The reader process will be suspended.
What happens if the buffer in a pipe is full?
The writer process will be suspended.
What is the purpose of the pipe ‘|’ symbol in Linux?
It tells the shell to create a pipe, connecting the output of one process to the input of another.
What is the difference between unnamed and named pipes?
Unnamed pipes:
- are temporary and used by related processes
Named pipes (FIFOs):
- are permanent and can be used by unrelated processes.
What system call is used to create an unnamed pipe?
pipe()
What are the two file descriptors returned by the pipe()
system call?
reading (p[0])
writing (p[1])
What happens if a process tries to write to a full pipe?
The writer process will be suspended until there is space in the pipe.
What happens if a process tries to read from an empty pipe?
The reader process will be suspended until data is available in the pipe.
What is the default behavior of pipes regarding data flow?
Pipes treat data on a first-in-first-out (FIFO) basis.
What is the minimum size of an unnamed pipe in most systems?
512 bytes
(depends)
What system call is used to create a named pipe (FIFO)?
mkfifo()
or mknod()
What is the advantage of using named pipes over unnamed pipes?
Named pipes can be used by unrelated processes and have a larger buffer capacity.
What is the purpose of the fcntl()
function in non-blocking I/O?
To set the O_NONBLOCK
flag, which prevents blocking when reading from or writing to a pipe.
What does the O_NONBLOCK flag do when set on a pipe?
It makes read and write operations non-blocking, returning immediately even if the pipe is empty or full.
What is the purpose of the fstat()
function in IPC?
To obtain file’s metadata when have an open file descriptor.
To get the number of characters in the pipe using the st_size
member of the stat structure.
What is the main drawback of unnamed pipes?
They cannot be used by unrelated processes and are temporary.
What is the typical buffer capacity of a named pipe (FIFO)?
Around 40K bytes
What is the purpose of the wait() system call in IPC?
To avoid zombie processes by waiting for child processes to terminate.
What is the difference between a unidirectional and bidirectional pipe?
unidirectional pipe:
*allows data flow in one direction
bidirectional pipe:
*allows data flow in both directions.
What is the purpose of the close() system call in IPC?
To close file descriptors associated with a pipe when they are no longer needed.
What is the purpose of the fork()
system call in IPC?
To create a child process that can communicate with the parent process using pipes