黑苹果惹的祸。EDUP USB无线网卡的管理工具不响应了。找不到它的安装位置,不知道从哪里重新打开。于是有了这个需求。幸好监视器还能看到 PID。
系统 (OSX 10.9.4)
思路是使用 lsof 命令查看程序的打开文件。剩下的就是字符串处理了。
代码示例:
lsof -a -p 1584 -d txt -Fn | cut -c2- | grep -E "(\S|\w|\s)*\.app(\S|\w|\s)*\.[a-zA-Z]*" -v | grep -E "(\S|\w|\s)*\.[a-zA-Z]{1,6}$" -v | grep app
lsof 几个参数说明
-a
且,将选项 selection
联合起来. 例: -a -U -ufoo
列出用户 foo
的进程使用的 UNIX socket 文件
-p
指定 PID
-d
指定文件描述 (FDs)
-F
输出到其它程序 OUTPUT FOR OTHER PROGRAMS
交由其它程序处理. n
指输出文件名
lsof 输出示例:
# lsof -p 1584
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
StatusBar 1584 root cwd DIR 1,6 1088 2 /
StatusBar 1584 root txt REG 1,6 630880 103307136 /Library/Application Support/WLAN/StatusBarApp.app/Contents/MacOS/StatusBarApp
... ...
... ...
... ...
lsof 输出示例:
#lsof -a -p 1584 -d txt -Fn
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/MacOS/StatusBarApp
n/System/Library/CoreServices/Encodings/libSimplifiedChineseConverter.dylib
n/usr/share/icu/icudt51l.dat
n/System/Library/Caches/com.apple.IntlDataCache.le.kbdx
n/System/Library/ColorSync/Profiles/Generic RGB Profile.icc
n/System/Library/ColorSync/Profiles/Generic Gray Profile.icc
n/System/Library/ColorSync/Profiles/sRGB Profile.icc
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/USBWiFi.ico
n/System/Library/Keyboard Layouts/AppleKeyboardLayouts.bundle/Contents/Resources/AppleKeyboardLayouts-L.dat
n/System/Library/PrivateFrameworks/CommerceKit.framework/Versions/A/Frameworks/CommerceCore.framework/Versions/A/CommerceCore
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarConnecting_0.pdf
n/System/Library/ColorSync/Profiles/Generic Gray Gamma 2.2 Profile.icc
n/private/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/C/com.apple.LaunchServices-0440.csstore
n/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras2.rsrc
n/System/Library/PrivateFrameworks/CoreUI.framework/Versions/A/Resources/SArtFile.bin
n/System/Library/Fonts/LucidaGrande.ttc
n/System/Library/PrivateFrameworks/FamilyControls.framework/Versions/A/FamilyControls
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarSignal_disconnect.icns
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarConnecting_1.pdf
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarConnecting_2.pdf
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarConnecting_3.pdf
n/System/Library/Fonts/Keyboard.ttf
n/private/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/C/com.apple.scriptmanager2.le.cache
n/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/HIToolbox.rsrc
n/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/English.lproj/Localized.rsrc
n/System/Library/Fonts/Helvetica.dfont
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/ScanListSignal_4.pdf
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/ScanListSignal_3.pdf
n/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/ImageFormats/unorm8_bgra.dylib
n/System/Library/Fonts/STHeiti Light.ttc
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/locked_w.icns
n/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/ScanListSignal_0.pdf
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/ScanListSignal_2.pdf
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarSignal_3.icns
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarSignal_5.icns
n/Library/Application Support/WLAN/StatusBarApp.app/Contents/Resources/BarSignal_4.icns
n/usr/lib/dyld
n/private/var/db/dyld/dyld_shared_cache_i386
结果:
/Library/Application Support/WLAN/StatusBarApp.app/Contents/MacOS/StatusBarApp
参考: