Question
Hi I have searched various forums and here as well, I could find some answers for Linux and Mac but not able to find solution for Unix and specially Korn Shell.How to get process name (command name) from process id (pid)
Below reference I found from SO This one And this one also.
How-To
I think it is easier to use pgrep. For example:
Otherwise, you can do it as follows:
- ps -ef | awk '$8=="name_of_process" {print $2}'
Better way: Let's check the last column ($NF), no matter its number:
If you want to match not exact strings, you can use ~ instead:
- ps -ef | awk '$NF~"gnome-pty-helper" {print $2}'
* Awk Introduction Tutorial – 7 Awk Print Examples
沒有留言:
張貼留言