Networking Forums

Networking Forums > Computer Networking > Linux Networking > UNIX Sockets, unlink() and accept()

Reply
Thread Tools Display Modes

UNIX Sockets, unlink() and accept()

 
 
Russ Lewis
Guest
Posts: n/a

 
      08-01-2003, 10:39 PM
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

 
Reply With Quote
 
 
 
 
beltorak
Guest
Posts: n/a

 
      08-02-2003, 06:40 AM
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.
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reliability of SOCK_DGRAM Unix-Domain sockets Kai Hergenroether Linux Networking 0 09-25-2006 09:52 AM
accept trouble stef Linux Networking 1 09-19-2005 11:50 PM
listen() and accept() Amit Yadav Linux Networking 1 01-09-2005 02:50 PM
getting client ip before accept? Stephan Dreyer Linux Networking 4 09-26-2004 03:08 AM
Unnamed Local/Unix Sockets Frank A. Uepping Linux Networking 0 12-04-2003 07:40 PM



1 2 3 4 5 6 7 8 9 10 11