macos - xargs 不适用于 lsof

标签 macos xargs lsof

当我运行 pgrep vim | xargs echo,它打印 93868 91234

当我运行 lsof -p 91234 时,它会打印:

COMMAND   PID USER   FD   TYPE DEVICE  SIZE/OFF    NODE NAME
vim     91234 rose  cwd    DIR    1,2      1326 1186863 /Users/rose/spotapi/spotapi/models
vim     91234 rose  txt    REG    1,2   1629296   12231 /usr/bin/vim
vim     91234 rose  txt    REG    1,2   2704416  294199 /System/Library/Frameworks/Python.framework/Versions/2.7/Python

为什么会这样

pgrep vim | xargs lsof -p 

打印

lsof: status error on 91234: No such file or directory

我在 Mac 操作系统上运行。

最佳答案

我在我的 Slackware 安装上看到了这个。如果您运行 lsof -p 93868 91234,您将看到问题所在。原因是 xargs 如果可以的话,将所有参数都推送到一个命令行中。您可以使用 -n 选项来指定参数的最大数量。

pgrep vim | xargs -n1 lsof -p

关于macos - xargs 不适用于 lsof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18817864/

相关文章:

android - 如果文件在 Android 设备上,是否可以通过 adb 安装 APK?

linux - 对 xargs 生成的命令的各个结果执行 grep

c - lsof 总是报告偏移量等于 OSX 中的文件大小

linux - 哪个线程监听特定的 UDP 端口

reactjs - zsh : command not found: netlify on mac OS

macos - 管道和正则表达式 bash 输出

iphone - Objective-C 中的 3DES 加密

python - xarg 与 python 多处理+子进程的性能对比

linux - Linux 中花括号的评估

linux - 如何检查文件是否在 Linux 中打开?