2

I used netstat to acquire RefCnt column. And there are 2 attached processes via /var/run/mysqld/mysqld.sock. How to find their PIDs?

# netstat -a -p -A unix

Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path
...
unix  2      [ ACC ]     STREAM     LISTENING     1432153  7517/mysqld         /var/run/mysqld/mysqld.sock
...

1 Answer 1

1

I think this is a trick question :)

Under the column PID/Program name there is 7517/mysqld. The 7517 is the PID. Is that what you were looking for?

You could also do a

ps -auxww | grep 7517

Just to verify

EDIT:

You can use pgrep -P pid to get the pid's of the other processes. You can use this short Bash script to give you more details, replace "YOUR_PID" with the pid from netstat:

for x in `pgrep -P *YOUR_PID*`; do ps auxwww | grep $x; done

6
  • I am looking for processes that are using this socket. According to the RefCnt column(as i mentioned in the original question) it must be two pids, not one, as you suggested. I am not looking for the process that open socket, i am looking for all process that using it. Jun 14, 2017 at 6:30
  • Does the updated answer give you what you're looking for?
    – Biyau
    Jun 14, 2017 at 6:54
  • 1
    No, you are totally wrong and you don't understand my original question and my comment at all. Jun 14, 2017 at 8:24
  • I'm fairly certain I do understand what you're asking. That PID from netstat is the Parent PID of the attached processes, take that and put it after pgrep -P and it will return exactly the pids of those child/attached processes. If you then look up those pids with ps you can see the details. I've been a Unix-Network admin for over 35 years.
    – Biyau
    Jun 14, 2017 at 9:51
  • thanks for the detailed answer, my bad, i did not get you right about parent pid. Unfortunately, on ubuntu 16.04, it does not work - there are no childs for the 7517 PID. I tried to verify other processes child count against their RefCnt column - they does not match(usually processes child count less then RefCnt). Not sure that RefCnt is the child process count that opened the socket. And in the netstat(8) RefCnt is called "The reference count (i.e. attached processes via this socket)." - does not looks like "reference" meant to be the child process. Jun 14, 2017 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .