Russ Lewis <spamhole-2001-07-(E-Mail Removed)> wrote in message news:<I_BWa.278$(E-Mail Removed)>...
> I am using UNIX sockets for some interprocess communication. I have a
> thread in the server blocking on accept().
>
> What I wanted to do was to be able, from another thread (perhaps even
> another process) to tell the server to cleanly terminate. I was
> figuring that I could do this by unlink()ing the socket; I figured that
> this would cause accept() to terminate with an error.
>
> However, this is not the case; apparently, since the server still has
> the open socket to the inode, the inode is not cleaned up and the server
> continues to wait. Thus, the blocked thread will block forever (until I
> Ctrl-C it).
>
> Is there a better way to do this?
>
> If it happens to matter, I am using Linux 2.4.x.
>
> Russ Lewis
Correct; according to the man page, the socket remains open and
available for use until the last process using it closes it.
Solution: write a signal handler for either HUP or USR1 to close the
socket and terminate. Install the signal handler after you create the
socket, then send that signal to the process/thread to cleanly
terminate. The signal handler will be executed even if the process is
blocking on read.
man setsigaction for more info.
-t.
|