user3627319
user3627319

Reputation: 425

How to get only the Process name using Process ID in unix

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

Answers (2)

Roberto Reale
Roberto Reale

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

glenn jackman
glenn jackman

Reputation: 247210

If you system uses the /proc filesystem:

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

Upvotes: 0

Related Questions