"Socket" files?

P

Paulo da Silva

How are those "files" of type "socket", whose name
begins with "=", created? How can I create them with
python?

Thanks.
 
M

Marcos Dione

How are those "files" of type "socket", whose name
begins with "=", created? How can I create them with
python?

they don't start w/ =; that's just ls being verbose. try 'ls -1'.

you can create them with os.mkfifo. see lib doc, section 6.1.4.
 
I

Irmen de Jong

Marcos said:
they don't start w/ =; that's just ls being verbose. try 'ls -1'.

you can create them with os.mkfifo. see lib doc, section 6.1.4.

mkfifo creates fifo nodes, not "socket"-type files.
I think Unix domain sockets are what the OP means...
Which are created by using the AF_UNIX socket type:

from socket import *
sock=socket(AF_UNIX,SOCK_STREAM)
sock.bind("/tmp/mysocket")

BTW, my ls lists them in pink, with a '=' at *the end*.
That's on Mandrake 10.

--Irmen
 
P

Paulo da Silva

Marcos Dione wrote:
....
they don't start w/ =; that's just ls being verbose. try 'ls -1'.

you can create them with os.mkfifo. see lib doc, section 6.1.4.

This seems to work. At least ls gives the same result.
Thank you.
 
P

Paulo da Silva

Irmen said:
Marcos Dione wrote:
....


mkfifo creates fifo nodes, not "socket"-type files.
I think Unix domain sockets are what the OP means...
Which are created by using the AF_UNIX socket type:

from socket import *
sock=socket(AF_UNIX,SOCK_STREAM)
sock.bind("/tmp/mysocket")
....
This seems more logical. Besides there is also a "file" type
"fifo" where I was using mkfifo.

I'll give it a try. Unfortunately I began to upgrade my Gentoo
Linux and I am busy now.

Thank you.
 
P

Paulo da Silva

Paulo said:
....


...
This seems more logical. Besides there is also a "file" type
"fifo" where I was using mkfifo.

I'll give it a try. Unfortunately I began to upgrade my Gentoo
Linux and I am busy now.

OK. It works! I'll use mkfifo for "fifo" type and this for
"socket" type.
BTW, don't I need to close "sock.close()"? I don't want to
do anything with the socket except keeping it on disk.
 
O

Oliver Fromme

Paulo da Silva said:
> > from socket import *
> > sock=socket(AF_UNIX,SOCK_STREAM)
> > sock.bind("/tmp/mysocket")
> [...]
>
> OK. It works! I'll use mkfifo for "fifo" type and this for
> "socket" type.
> BTW, don't I need to close "sock.close()"? I don't want to
> do anything with the socket except keeping it on disk.

Uhm, are you sure you know what you're doing? UNIX domain
sockets work very similar to Internet domain sockets, i.e.
they disappear when they're closed (or when your program
exits, in which case everything is closed implicitly).

Why exactly do you want to create one and keep it on disk
without doing anything with it? That doesn't seem make any
sense at all.

Best regards
Oliver
 
P

Paulo da Silva

Oliver said:
Why exactly do you want to create one and keep it on disk
without doing anything with it? That doesn't seem make any
sense at all.
Well, I never programmed anything using fifo or sockets.
What I need to do as part of a work is to get information
about some disk or a dir contents and then replicate it
later (something like a backup). I don't really know if
those "files" of type socket have any other role behind
sockets communication. So I thought of replicate them also.
I have seen that tar doesn't seem to "save" them, but cp does.
BTW, those "files" are kept after issuing close().

Thank you for your comments on this.
 
G

Greg Ewing

Oliver said:
Uhm, are you sure you know what you're doing? UNIX domain
sockets work very similar to Internet domain sockets, i.e.
they disappear when they're closed (or when your program
exits, in which case everything is closed implicitly).

Indeed. Last time I played with Unix-domain sockets (which
was quite some time ago, things may have changed since)
the entry in the file system seemed to be completely
useless -- you couldn't do anything with it that you
might expect, e.g. open() it. The docs described the fact
that a file system entry existed as a "side effect" that
might go away in future versions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top