On Monday, December 12, 2011 1:15:07 AM UTC+8, Tobias Müller wrote:
> Leigh Johnston <le...@i42.co.uk> wrote:
> > On 11/12/2011 14:41, oshaer wrote:
> >> Hi Everybody
> >>
> >>
> >> I need to write a code that forcibly closes connections that are in
> >> CLOSE_WAIT status. It should run at a father process and constantly
> >> check the forked child processes(servers). I need this code to work on
> >> Unix/Linux, thus usage of WINAPI is not possible.
> >>
> >> My question is:
> >>
> >> 1) Should I use netstat through code and parse the result to learn
> >> which socket is in a CLOSE_WAIT situation?
> >>
> >> 2) Is there any C++ code that enables me to easily get socket status,
> >> given the file descriptor number?
> >>
> >> 3) If you have any other ideas/recommendations please share.
> >
> > Off-topic.
> >
> > HTH.
> >
> > /Leigh
>
> Not everyone knows that sockets are platform specific and there is no
> standard C++ API. You could at least point that out.
>
> To the topic, I don't think that it is possible to close connections of a
> different process. You can just kill those processes.
> But a connection in CLOSE_WAIT just means that the other peer has already
> closed the connection. If the child process is implemented correctly, it
> just closes those connections and there won't be any zombie connections.
>
> Tobi
This kind of trivial jobs in shell scripts that can be invoked by a C++ program
to spawn a process is really boring.
In POSIX compatible OSes the standard output can be directed to a file.
|