ps comm format always cuts the process name

3

1

I am trying to invoke ps -o comm:1024 --pid 1391 --cols 1024 -w in the hope of getting the full process name (and only that), but I always end up with this

COMMAND
notification-ar

while the process name is instead notification-area-applet. I also tried all combinations of -w, --cols and : formatter. cmd and args give the full path and arguments of the process. I might be able to get the process name from these, but still...

Stefano Borini

Posted 2013-03-18T08:51:54.913

Reputation: 2 034

Related: https://askubuntu.com/questions/717919/how-to-prevent-ps-from-truncating-the-process-name

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2019-08-26T20:35:07.397

Answers

5

The comm field (also /proc/$pid/comm) is limited by the kernel to 16 bytes total (15 characters + terminating NUL byte).

If the system is Linux and you own the process (or are root), you can obtain the executable path by following /proc/$pid/exe using the readlink command.

Otherwise, you will have to use the cmd field (aliases args, command). On Linux it's taken from /proc/$pid/cmdline (which is NUL-separated), so you can also use cut -d "" -f 1 /proc/$pid/cmdline.

Beware that both cmdline and comm can be changed by the process itself.

user1686

Posted 2013-03-18T08:51:54.913

Reputation: 283 655