Reputation: 425
I want to get the process name(not the entire process information) when I have the process ID.The command I need should only return the process name.
Upvotes: 2
Views: 3497
Reputation: 4317
You can try
ps --pid <pid> -o cmd h
where
--pid <pid> specifies the process' PID
-o cmd tells ps to only print the command name
h suppresses headers
if you want the command with all its arguments; or
ps --pid <pid> -o comm h
if you want only the executable name.
Upvotes: 4
Reputation: 247210
If you system uses the /proc filesystem:
cut -d "" -f 1 /proc/$pid/cmdline
Upvotes: 0