如何在unix中仅使用进程ID获取进程名称

时间:2014-05-12 09:28:51

标签: shell unix process command

当我有进程ID时,我想获取进程名称(而不是整个进程信息)。我需要的命令应该只返回进程名称。

2 个答案:

答案 0 :(得分:2)

你可以尝试

ps --pid <pid> -o cmd h

,其中

--pid <pid>        specifies the process' PID
-o cmd             tells ps to only print the command name
h                  suppresses headers

如果你想要命令及其所有参数;或

ps --pid <pid> -o comm h

如果您只想要可执行文件名

答案 1 :(得分:0)

如果您的系统使用/ proc文件系统:

cut -d "" -f 1 /proc/$pid/cmdline