This library can help you to get a list of running processes, get a list of tcp ports opened by the process, and find a process by the tcp port it opened.
Just pass the pid of process to the function getLocalTcpPorts(of: pid_t)
.
let result = getLocalTcpPorts(of: 56605)
print(result)
It's quite easy to get all the TCP ports opened by one process with a command.
lsof -nP -p <pid> -a -i4TCP
However, if you need to do the job programmatically with Swift in macOS. There's no available documented API to do this.
So I use below functions from libproc
just like the command lsof
do.
Just use getAllProcess()
.
for process in getAllProcess() {
print(process.pid, process.name)
}
let process = getProcess(from: 13659)
link |
Stars: 1 |
Last commit: 2 weeks ago |
Make ProcessProfile totally public! ๅ ฌๅผProcessProfile็ๆๆๆๅ๏ผ
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics