Create file socket linux
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto | Site FAQ | Sitemap | Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
|Introduction to Linux – A Hands on Guide |
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author’s experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
i’m not so sure you can make that by hand — seems like the programm will have to
was it in /tmp
if so it might just be a link to something like
ln -sf /var/lib/mysql/mysql.sock /tmp/mysql.sock
or something like that
otherwise seems like a restart
mysqladmin [-h . -u . -p. ] shutdown
mysqld_safe –user=mysql &
if it’s suposed to be in tmp make sure mysql has write permission
That has got to be one of the biggest problems with MySQL!
Everyone everywhere is getting this stupid can’t connect on mysql.sock and there is nothing at their site or on the Internet saying why this happens.
Further, there should be a way to make a simple socket file, and you can’t find that anywhere either.
From what I’ve read, the temporary file is created in the mysql directory, while KDE tries to create her own sockets, temporary ones in /tmp
There are problems with pthreads, and so on, but if the MySQL development team would go after this bug, they might get a lot of disconnection errors fixed.
The distribution should come with a copy of the socket file and not depend on C++ to have one compiled in without any recourse.
It really is beginning to look like MySQL team did not know what it was doing with sockets, auths, and a lot more. A socket should be a simple thing and it should work, without the really stupid error message “can’t connect using socket,” of course it can’t connect dummy, but why can’t it connect?
here, I created the mysql.sock file and echo’ed a null character to it. I created this in /var/run/mysql but as it turns out the file created is a pipe and not a socket, which may dismay the author of the other article a bit. Perhaps there is a mksocket command [no such luck!].
If you found an answer, please reply.
This topic was originally posted about 2.75 years ago. Has anyone
figured out in the interim how to create a “socket file”? They are
sitting here on this Linux machine I am using, eg:
bash> ls -F /tmp/.X11-unix/X0
bash> file /tmp/.X11-unix/X0
I have been totally unsuccessful in finding a program or series of
programs which will create one of these puppies for me. I have an
application which takes input only from such a beast and I want to
be able to pump bits at it. And as has been pointed out in other
threads, a file socket is NOT the same thing as a file pipe.
Probably I just don’t have the right jargon for it. Pardon my *X
ignorance. Just as the Unix creators thought it appropriate that
a program named “biff” would tell us that mail had arrived (because
the guy who wrote the program had a dog named Biff which barked at
the postman), we should probably JUST KNOW that something similar
exists in this case. How about a program called “cardiac-arrest”
for creating a “file socket”, so named because cardiac arrest is
what can happen when you stick a real (ie steel) file into a real
(ie 120 volt) socket? (Hot side with your other hand on a pipe,
of course.) Or some such.
So, can anyone answer this question now?
I even forgot that I posted this ! I kinda lost touch with Linux in a while so thanks for reminding me that this world still exists !
However, I remember that at that time I did not find any utility that could create a socket file and I ended up in reinstalling my box.
Now that you brought this back into my attention I have done a little search in the web and maybe this will help you a little:
You have to write some code in order to create the socket file, but I really don’t have any idea about how the code should look like since I know nothing about programming with gcc.
I really hope this will give you a clue and I’m really sorry for not being able to provide more consistent information.
mysql.sock is a fifo file. It is essentially a bidirectional pipe “|” that exists as a file so that processes can talk to eachother without going to all the trouble of using network sockets.
see the options for mkfifo. on my system the file is:
srwxrwxrwx mysql mysql
Also note that you should double check /etc/services and make sure mysql is listed in there (default port 3306).
Lots of misunderstanding here; let’s see if I can clarify.
A socket file is not a regular file, it’s more like an IP address (it is also not a fifo, although those are similar). A socket file is created by the system when a program calls bind on a unix domain socket, which is a special kind of network socket that can only be internal to one computer. The system then associates this special file with the socket file descriptor that the program bound (or more specifically, the “inode” to which that file descriptor refers).
From that point on, the program that created the socket has no interaction with the socket by the filename. If you move it elsewhere, create new links to it, or remove it, you may confuse other programs that are trying to talk to the program in question, but the program itself won’t see it at all. You are only changing the set of names that point at that inode (and you can connect to the listening program at that new name!). Thinking of the filename as a domain name, the inode as the ip address, and the filesystem as DNS isn’t so very far off.
So considering, in this case, mysqld and it’s socket. As should be apparent (I hope) from the above, copying a socket file created by some other program to /var/run/mysql.sock isn’t going to help re-establish communication with the mysql server – you’ve just pointed the filename you want at a different inode, and it will mean that other program (if it is still alive) will be receiving the connections that should be going to mysqld; not what we want at all. What is needed is for mysqld itself to recreate the socket.
So, how can we make it do that? Per http://www.pathname.com/fhs/pub/fhs-2.3.html, the /var/run filesystem is the place for run-time variable data and should be cleared out at each boot. So a restart of the computer should do it. But that’s ugly. We should be able to just restart the service (it would be even nicer if a reload would do it, but I’ve tested and it doesn’t). So ideally, the init scripts should handle this and on the version of ubuntu I’m in front of they do. Here,
sudo service mysql restart
works just fine after removing /var/run/mysql.sock, and the file is recreated. If that doesn’t work, you can try running the init scripts manually with something like
sudo /etc/init.d/mysqld restart
If that still doesn’t work, then you need to bring it down some other way. Per http://dev.mysql.com/doc/refman/5.0/. -response.html we see that a TERM signal will safely shut down the server, so we can say
to get the pid of the running server (as mysqld is not so well behaved as to provide us with a pid file, but no biggie), and then (replacing 12345 with the pid we found):
Linux named sockets howto
I know that there are named sockets & named pipes (fifo) in Linux.
In ls -l , they would look as below: (I have changed the filenames, for demonstration.)
Now, a named pipe can be created using mkfifo . Is there a command for creating a named socket?
Last option would be to write a C program, which would call mknod function, but wanted to know, if there is already a command for that.
What I have tried:
I tried to search for any options to mknod & mkfifo, but could not find one.
NOTE: I am not discussing about server-client model over Ethernet/network. The named socket file will be used by 2 processes on the same system.
3 Answers 3
A Unix/Linux socket file is basically a two-way FIFO. Since sockets were originally created as a way to manage network communications, it is possible to manipulate them using the send() and recv() system calls. However, in the Unix spirit of “everything is a file”, you can also use write() and read() . You need to use socketpair() or socket() to create named sockets. A tutorial for using sockets in C can be found here: Beej’s Guide to Unix IPC: Unix Sockets.
The socat command line utility is useful when you want to play around with sockets without writing a “real” program. It is similar to netcat and acts as an adapter between different networking and file interfaces.