1

So I opened a socket connection like was described here I want to let other processes use that open connection. Will dup() help me or what shall I do?

Community
  • 1
  • 1
Rella
  • 65,003
  • 109
  • 363
  • 636
  • You mean like this: http://stackoverflow.com/questions/5312773/c-application-is-it-possible-to-pass-accepted-tcp-connection-from-one-process/5312831#5312831 ? `dup` isn't going to be helpful here at all. – Fred Foo Mar 18 '11 at 09:02
  • yep... but it would be so much cooler to perform that black magic in less than 10 lines...=) – Rella Mar 18 '11 at 10:04
  • Just as a side note, the Unix way is to create a socket in a process and then use `fork()`. That child process inherits all the sockets (unless they were opened with `O_CLOEXEC`). That way is really easy in Unix. Much harder in Windows... Each OS has its pros and cons. – Alexis Wilke Nov 10 '15 at 09:59

1 Answers1

2

In order to pass sockets between existing processes you need to use sendmsg - Or libancillary which abstracts the whole thing.

Erik
  • 88,732
  • 13
  • 198
  • 189