Getting the status of a socket through code

O

oshaer

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.

Thanks a lot.
Ofira.
 
V

Victor Bazarov

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.

Sockets are platform-specific. Please consider asking in the newsgroup
dedicated to your OS/platform.

V
 
T

Tobias Müller

Leigh Johnston said:
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
 
8

88888 Dihedral

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.
 
J

Jorgen Grahn

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.

Like others mentioned, go seek advice in some Unix/Linux/POSIX group,
and/or refer to W R Stevens' books. Also mention there what the actual
problem is that you're trying to solve -- the way you're trying to do
it is almost certainly the wrong approach.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top