Need some help in 'exec' command in unix!

Sai Venu Gopal. Sunkara sai.sunkara@wipro.com
Wed, 22 Dec 1999 09:38:04 +0530 (IST)


Hi,
	I got the problem solved....
	It's like this :
	
	When any sockets are opened before a fork(), If we do an
	'exec' in the child process, the sockets are still open.
	But, we need to explicitly pass the value of the socket
	descriptor. In the exec'ed process, we need to retrieve 
	the socket descriptor and use it as usual.
	
	I couldnot solve it quickly as I didn't know how to do
	it. But, by trial and error, it worked...

Thanks and Regards,
Sai/...

On Tue, 21 Dec 1999, Kragen Sitaker wrote:

> I'm not sure this is *exactly* on-topic, but I'll answer it anyway:
> 
> Sai writes:
> > 		if(ns is valid)
> > 		{
> > 			switch( pid = fork() )
> > 			{	
> > 			 case 0: /* child */
> > 				if(some condition)
> > 				{
> > 					exec(executable '/bin/newexe');
> > 	
> > 	Now, the executable '/bin/newexe' needs to do some processing,
> > 	and send back some data on the socket 'ns'.
> > 
> > 	Here, exists my real problem.
> > 
> > 	'ns' exists in the memory of the child process. When we do an
> > 	'exec', the child process image gets overwritten the image of
> > 	the newly executed executable. But, I want to have the right
> > 	to write back to the socket 'ns'.
> 
> Well, there are two problems.  One is the close-on-exec flag, which I
> think you can solve with fcntl(ns, F_SETFD, ~1 & fcntl(ns, F_GETFD)),
> and the other one is communicating the knowledge of ns's numerical
> value.
> 
> The usual solution for this is to agree on a particular numerical
> value, such as 0 (stdin) or 1 (stdout).  Or both.  Then you can use
> close() and dup(), or just dup2(), to get the socket attached to those
> file descriptors, and then you can close the original fd, as close(ns).
> 
> HTH.
> 
> -- 
> <kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
> The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
> <URL:http://www.pobox.com/~kragen/bubble.html>
> 
> 
> -- 
> Kragen-discuss is intended to be used to discuss things I send to
> kragen-fw, kragen-hacks, kragen-journal, and kragen-tol.  You can 
> unsubscribe at kragen-discuss-unsubscribe@kragen.dnaco.net.
> 
>