Home > Net >  How to locate the unix socket of a particular process
How to locate the unix socket of a particular process

Time:01-19

For a local MySQL connection, how would I find the unix socket number of the location connection? I don't believe it's in the ps command:

USER           PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
_mysql         141   0.0  0.0 34786180   3284   ??  Ss    6Jan22  16:21.85 /usr/local/mysql/bin/mysqld...

Is there a simpler way to find that?

enter image description here

CodePudding user response:

Here is an example of viewing the process(es) that have a given file open:

$ lsof /tmp/mysql.sock

COMMAND PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mysqld  829 bkarwin   21u  unix 0x1c2b10907d83adad      0t0      /tmp/mysql.sock

Or go the other way, listing all files open for the process id of mysqld:

$ lsof -p 829

COMMAND PID    USER   FD     TYPE             DEVICE  SIZE/OFF                NODE NAME
...
mysqld  829 bkarwin   21u    unix 0x1c2b10907d83adad       0t0                     /tmp/mysql.sock
...

If you don't know the process id, you can make lsof search for a process whose command starts with a given string:

$ lsof -c mysqld
(same output as for -p)

Read https://ss64.com/osx/lsof.html for more usage.

  •  Tags:  
  • Related