Search code examples
cunixfile-descriptor

Is a file descriptor local to its process or global on Unix


int fd = socket(//arguments);

Can this descriptor be passed to another process via IPC and still be valid or is it local to the process that created it?


Solution

  • Yes, file descriptors are local to the process. When a process forks a child, however, the parent and child have the same file descriptor table. This is great because it allows for IO redirection, which is a pretty handy trick.