0

I have a listener which spawns a child each time he accepts() a connection. I'd like the children to then manage their socket on their own. Since I can communicate with the children through pipes, I'd like to know if I can send the socket through it. Thanks in advance !

Kiel
  • 1
  • 1
  • You cannot use a pipe but a socket to transfer a file descriptor. See [Can I share a file descriptor to another process on linux or are they local to the process?](https://stackoverflow.com/questions/2358684/can-i-share-a-file-descriptor-to-another-process-on-linux-or-are-they-local-to-t) – Steffen Ullrich Jul 27 '17 at 15:55
  • 1
    Apart from that - if you fork the children anyway after the accept it will already inherit the fd - thus no need to transfer it through a pipe or similar. – Steffen Ullrich Jul 27 '17 at 15:57
  • OK thank you. The thing is I'm not forking, but spawning. I know the children can inherit the fd even with a spawn(), but I don't get how to use this inheritance. I'm spawning another program, so the code and variables are not the same. So how should I declare the fd in the child ? Should it be a parameter or just a local variable ? Anyway, I think I'll stick to the socket to transfer the fd, it was my first idea anyway. – Kiel Jul 28 '17 at 08:04

0 Answers0