Problem closing socket/terminating process

Hi,

I have an application I’m trying to create on QNX 6.2.1. It has a process
that opens a TCP socket, sets socket options, binds to a well-known port,
listens, accepts a connection, then duplicates the file descriptor. Next,
it creates two threads; the first one which is a server and which uses the
“read” socket to “recv” packets, and, a second one which uses the duplicated
socket descriptor to send packets. At some point, I need to shut this
process down and spawn another process that needs to use the same well-known
TCP port. My problem is that the original process sometimes simply won’t
terminate and this occurs when there are packets that have been recently
recv’d. In this case, netstat shows the connection is ESTABLISHED (not
TIME_WAIT because the process is still alive), and, this perists until I
terminate the client’s connection (on the client computer). I’ve tried just
about everything, including variations on having the original process use
“shutdown” followed by “close”, setting the socket options for SO_LINGER to
indicate that unsent data should be immediately discarded, using KILL to
send a SIGKILL signal and drinking scotch until I can’t see straight
(doesn’t seem to help either).

So, sorry to be so long-winded, but here are my questions:

  1. Is this behavior peculiar to QNX, or, would I expect to see the same
    thing on Linux or a Unix implementation?
  2. Do you have any bright ideas that might help (right now, the best I can
    do is to re-architect my app to make it unnecessary to shutdown the original
    process)?

Thanks,

Eric Franz
Ricanz Corporation