DeadHead@cup.portal.com (Bruce M Ong) (10/18/90)
Hi - I have a question w/ regard to passing open file descriptors from a parent to a child that's spawned with 'exec' not 'fork'. Basically, how to do it right? I have a parent process that makes a socket connection with a remote server. And depending on a server reply message type, I want the parent process to exec another program (the parent process will go away, with the new program replacing it). However, i dont want to close the connection and open the connection again from the new program - I want the new program to inherite the open socket descriptor and continue to talk to the server, without the server knowing that the client has gone through a metamorphosis. Any hints or where can I find some source example, (does the BSD inetd do something like this?) would be much appreciated. thanks - bruce deadhead@cup.portal.com
olano@currituck.cs.unc.edu (Thomas Olano) (10/19/90)
In article <34954@cup.portal.com> DeadHead@cup.portal.com (Bruce M Ong) writes: ... > I have a parent process that makes a socket connection with a remote >server. And depending on a server reply message type, I want the parent >process to exec another program (the parent process will go away, with >the new program replacing it). However, i dont want to close the connection >and open the connection again from the new program - I want the new program >to inherite the open socket descriptor and continue to talk to the server, When I did something similar, I passed the open socket descriptor to the child using environment variables. This may not be the "easiest" or "best" way to do it, but hey, it worked! Essentially the parent set an environment variable with putenv() and the child read it with getenv(). Perhaps a more elegant method would be to pass the descriptor as an argument in the exec call. The default is for files and sockets to remain open over and exec so everything should be happy. Marc Olano olano@cs.unc.edu no cute signature
3003jalp@ucsbuxa.ucsb.edu (Applied Magnetics) (10/19/90)
In article <16903@thorin.cs.unc.edu> olano@currituck.cs.unc.edu (Thomas Olano) writes: >In article <34954@cup.portal.com> DeadHead@cup.portal.com (Bruce M Ong) writes: >... >> [wants to open a socket and pass it through an exec()] > >When I did something similar, I passed the open socket descriptor to the >child using environment variables. [...] Sockets remain open across the exec. If I understand the question correctly, the problem is to tell the exec'd process which descriptor carries the socket? You should be able to open the socket, then use dup2(2) to force it onto a pre-agreed descriptor. This way, you don't need to pass anything. Disclaimer: I haven't tried this. Nor has my employer. --P. Asselin, R&D, Applied Magnetics Corp.