Re: execve(): unexpected socket behavior
- From: Henry Townsend <henry.townsend@xxxxxxxx>
- Date: Fri, 06 Oct 2006 16:32:23 -0400
Simple Simon wrote:
Linux 2.6.11 i686
gcc 3.3.5
clib 2.3.4
I have a process which opens and writes to a TCP socket, which at regular intervals I replace with another instance of the process via execve().
Technically it remains the same process all the way through. What you have is another instance of the *program* running in the same *process*.
If I do a 'netstat -t', I see a growing list of ESTABLISHED connections, one for each execve()'ed instance, with only the current instance (most recent connection) actually used.
So: Each instance of the process is correctly inheriting the previous set of open descriptors. I have been unable to figure out how to reference them, however, so I can determine (in successive instances) when I already have an open socket and so don't have to open another one.
This reduces to detecting when an instance is the first instance of the process, and when it is an execve()'ed instance.
The socket descriptor is a file scope variable, so is automatically initialized to 0 when the process loads. I had thought that this variable would be non-zero upon successive instances, but that isn't the case (so testing it for 0 as a condition of calling socket() doesn't work).
I'm scratching my head trying to figure out how to reference the inherited descriptor.
Any comment or pointer to a illuminating reference appreciated.
Set an environment variable to the value of the file descriptor. Then, if the EV exists (and assuming correct use of the CLOEXEC flag), you already have an open descriptor and the value of the EV tells you what it is. Otherwise you need to make one (and export it).
HT
.
- References:
- execve(): unexpected socket behavior
- From: Simple Simon
- execve(): unexpected socket behavior
- Prev by Date: execve(): unexpected socket behavior
- Next by Date: Re: Ctrl-C in script causing started process to terminate
- Previous by thread: execve(): unexpected socket behavior
- Next by thread: Re: execve(): unexpected socket behavior
- Index(es):
Relevant Pages
|
|