Path: utzoo!attcan!uunet!know!sdd.hp.com!usc!elroy.jpl.nasa.gov!ncar!gatech!mcnc!thorin!currituck!olano From: olano@currituck.cs.unc.edu (Thomas Olano) Newsgroups: comp.unix.programmer Subject: Re: Passing open file descriptor to the exec'ed process Message-ID: <16903@thorin.cs.unc.edu> Date: 18 Oct 90 17:04:02 GMT References: <34954@cup.portal.com> Sender: news@thorin.cs.unc.edu Reply-To: olano@currituck.cs.unc.edu (T Marc Olano) Distribution: na Organization: University Of North Carolina, Chapel Hill Lines: 21 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