Re: UNIX Sockets, unlink() and accept()
From: beltorak (beltorak_at_ananzi.co.za)
Date: 08/02/03
- Next message: Dan Harkless: "Fix for SuSE multiple hotplug network interfaces race condition?"
- Previous message: Andy Zhang: "Re: Packet forwarding"
- In reply to: Russ Lewis: "UNIX Sockets, unlink() and accept()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 1 Aug 2003 23:40:39 -0700
Russ Lewis <spamhole-2001-07-16@deming-os.org> wrote in message news:<I_BWa.278$9M3.42712@news.uswest.net>...
> 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.
- Next message: Dan Harkless: "Fix for SuSE multiple hotplug network interfaces race condition?"
- Previous message: Andy Zhang: "Re: Packet forwarding"
- In reply to: Russ Lewis: "UNIX Sockets, unlink() and accept()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|