Let’s say I create a socketpair() and I pass the handle of one of the socket to a spawned process (popen), will the said process be able to communicate back with the parent?
The examples I saw are applied using fork() which is out of scope for my current project.
Updated: I tried a simple test:
-
Client:
socketpairwith sockets[0] -
From Client use
posix_spawnwith sockets1 as command-line argument -
Client:
writeto socket … Client exits without any warning…
It would appear that there is a problem with this method.
UPDATED: I also found this note:
Pipes and socketpairs are limited to communication between processes with a common ancestor.
The man page for execve states:
Since functions like popen are based on execve, then the file descriptors that you got from your socketpair function should be good across both processes, and I don’t see why you can’t pass the descriptor in whatever manner pleases you. I’m assuming that in this case you mean to convert it to a string and set it over STDIN to the sub-process, which would convert it back to an int to use as a file descriptor.
It would certainly be worth writing some trial code for.