What PID is listening on this data port

My application receives IPC messages and returns responses for callers. I have a caller port(msgh_remote_port) and I want to know the caller's PID . Can I find on OSX the mach a PID port that is listening on a specific mach port?

+6
source share
3 answers

The machine port is not directly connected to the process, but instead to the task. Then the task is connected with the structure of the bsd process. To request the ports of a task, you can use the mach_port_names function. So that all open ports handle all tasks and use the above function.

Another approach is to use the procfs file system. The procfs file system is implemented on top of the fuse file system and must be manually installed on the system. This is an open source solution. After installing the procfs file system, you can request task ports by accessing the / proc / proc -id / task / ports file. Take a look at http://osxbook.com/book/bonus/chapter11/procfs/ .

+2
source

Three ways to do this without kext:

  • launchctl printing system (or other domain)
  • lsmp -a (no port names, only identifiers)
  • procexp all ports | grep the_service_name_you_want

    (procexp is an add tool from http://NewOSXBook.com/tools/procexp.html )

0
source

Source: https://habr.com/ru/post/908816/


All Articles