IPC

Work in Progress

Summary

File descriptor syscalls

SyscallIncludeFunction
read(fd, buff, count)<unistd.h>reads bytes from a file descriptor
write(fd, buff, count)<unistd.h>writes bytes in the buffer to a file descriptor
newfd = dup(fd)<unistd.h>duplicates a file descriptor
return a file descriptor that is the aliad of the one supplied
dup2(fd, newfd)<unistd.h>redirects one file descriptor to another
close(fd)<unistd.h>closes a pipe endpoint
pipe(p[2])<unistd.h>creates a pipe
returns two file descriptors

Concept

File descriptors

  • integer that the OS uses to identify a file or IO resource
  • each process maintains a fd table

yep, everything is a file

Standard channels

  • predefined channels for process IO
  • can be overwritten
  • fd = 0 -> stdin
  • fd = 1 -> stdout
  • fd = 2 -> stderr

bash