我已经创建了一个应该监听端口 50051 的服务,但是该端口已被使用。
所以我需要找到并杀死听众?
步骤1:
sudo lsof -i tcp:50051
Password:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
launchd 1 root 43u IPv6 0x9cf985f50f0e6545 0t0 TCP *:50051 (LISTEN)
launchd 1 root 44u IPv4 0x9cf985f50cb5056d 0t0 TCP *:50051 (LISTEN)
第2步:
find ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons -name "*.plist" -exec defaults read "{}" 2>/dev/null \; | grep --with-filename 50051
(standard input): SockServiceName = 50051;
步骤3:?
注意:我无法终止监听器,因为它是由 launchd 启动的。
lsof -ti tcp:500051 | xargs kill
答案1
这个成功了
find ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons -name "*.plist" -exec grep -H 50051 "{}" \; 2>/dev/null