linux - Bash:从 pid 获取规范路径和参数

标签 linux bash process pid

是否有一种简单的方法来获取运行某个进程 (pid) 的规范路径和参数。

例如,对于进程 1445,我想得到: /usr/bin/xclock -digital

我想做的是:

$ ls -l /proc/1445 | grep exe

得到类似的东西 ....... ->/usr/bin/xclock

然后

$ ps 1445 | cut -b 28- | tail -n 1

获取xclock -digital

最后将这两个输出放在一起。我认为这可行,但我认为应该有更好的方法来做到这一点。

非常感谢您的帮助。

最佳答案

您可以解析 /proc/$PID/cmdline 的内容以获取路径和参数(更多详细信息请参阅 How to parse /proc/pid/cmdline)。

规范路径可以通过realpath(1)获取。

关于linux - Bash:从 pid 获取规范路径和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408858/

相关文章:

json - 在 bash 中使用 jq 将 json 值提取为数组

c - 使用 fork(),如何让子进程始终先运行?

c# - 获取 C# 中实际可见的进程/窗口

c++ - 创建进程并在进程返回消息后运行代码(C++)

linux - 了解 Perf 工具输出

c - 在开始时使用 "\r"更新进度条字符串,跳过或错过迭代

node.js - 执行错误 : Error: stdout maxBuffer exceeded if using child_process on Node js

linux - Linux 中的隔离存储

linux - bash 4.3.42 。 : is/dev/fd/1 incorrect after redirecting or closing stdout?

linux - [ : : integer expression expected Error