LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2011, 03:21 AM   #1
tolekutma
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Rep: Reputation: 0
UNIX Domain Sockets


Hi,

I lately change my process to listen to unix domain socket instead of regular ports.

My problem is that the bind doesn't give an error as before in case of two instances of the processes.

I am using the UNIX domain sockets as dagram.

How can I achive the capability of avoiding of multiple instances of the process?

Thanks

(I am using C)
 
Old 03-08-2011, 08:25 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves. The Domain is the filesystem, not a network domain. You aren't trying to bind to a port, but using a file descriptor. So you won't get "bind: Address already in use" errors.
 
Old 03-19-2011, 04:04 AM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
In my opinion it should give an error. Can you post a code snippet?
 
Old 03-19-2011, 09:23 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by Mara View Post
In my opinion it should give an error.
The opinion is not just yours. W. Richard Stevens of happy memory says this about Unix domain sockets in UNIX Network Programming, volume 1:
Quote:
The bind will fail if the pathname already exists in the filesystem.
Quote:
Originally Posted by Mara View Post
Can you post a code snippet?
Yes, tolekutma, please do. Perhaps you delete that file before binding to it in each process. The result wouldn't be pretty, but nothing's to keep you from doing it.
 
Old 03-20-2011, 01:48 AM   #5
tolekutma
LQ Newbie
 
Registered: Sep 2010
Posts: 7

Original Poster
Rep: Reputation: 0
UNIX Domain Sockets - solved and more

Hi,

Thanks for your reply,

As you mention the UNI Domain Socket bind is going to failed,
in case of corresponding file exist in the system.

just for whom interest in it,
This raise another problem:
how to handle file that exist but thee isn't relevant process listen to this socket?
(for example, the file that created it crash and didn't erase it)

So, in UNIX Domain Socket you can use abstract names that let the OS to handle it by using hash table instead of creating a file.

This is done by creating names that start with (0).
 
Old 03-20-2011, 04:11 AM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by tolekutma View Post
This raise another problem:
how to handle file that exist but thee isn't relevant process listen to this socket?
(for example, the file that created it crash and didn't erase it)
Just before you bind, create a different file with some constant name, and lock this new file. If the lock fails, it's because someone else has done this and (presumably) also is using the socket. If the lock succeeds and the socket still exists, then the other program has crashed or otherwise exited without deleting the socket, and you can delete the socket and bind again.
Quote:
Originally Posted by tolekutma View Post
So, in UNIX Domain Socket you can use abstract names that let the OS to handle it by using hash table instead of creating a file.

This is done by creating names that start with (0).
Interesting concept, but I don't understand how it works. Could you give a small code sample?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to debug Unix domain sockets ? oknets10 Linux - Networking 3 12-25-2011 03:07 AM
Unix domain sockets - Resource temporarily unavailable svm Linux - Networking 2 11-22-2010 07:33 PM
Difference in UNIX Domain Sockets: SOCK_DGRAM vs SOCK_STREAM tm007 Programming 11 02-27-2008 12:25 PM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
IPtables - Active UNIX domain sockets LordDaemon Linux - Networking 2 11-12-2006 05:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration