pipe

int pipe(int p[]) 
// Create a pipe, put read/write file descriptors in p[0] and p[1].
// p[0] is read fd, p[1] is write fd
  • Writing data to one end of the pipe makes that data available for reading from the other end of the pipe.
  • Anonymous: Pipes are anonymous, meaning they do not have a name in the filesystem. They are used for communication between related processes (parent and child processes) or between processes explicitly sharing the pipe’s file descriptors.
  • Lifetime: A pipe exists only as long as the processes using it are running. It gets created with a system call (e.g., pipe() in C) and is destroyed when no more processes hold file descriptors for the pipe.
  • Scope: Typically used for simple, short-lived parent-child or sibling’s Inter Process Communication.
  • Usage: Created programmatically using system calls within programs. Cannot be accessed from the shell directly.

Named Pipe (FIFO)

  • Named: Unlike pipes, named pipes have a name in the filesystem. This means they can be accessed using this name by unrelated processes and persist beyond the life of the creating process.
  • Lifetime: A named pipe exists in the filesystem and remains until it is explicitly removed. It can be created with the mkfifo command or the mkfifo() system call.
  • Scope: Useful for communication between unrelated processes, possibly running at different times. They can be used by any process that has permission to access the named pipe’s file.
  • Usage: Can be used from shell scripts or programs, offering more flexibility compared to anonymous pipes.