Can I use standard tools to get the full name of a process, when its name has embedded spaces?

Posted by fred.bear on Ask Ubuntu See other posts from Ask Ubuntu or by fred.bear
Published on 2011-01-15T11:36:25Z Indexed on 2011/01/15 11:59 UTC
Read the original article Hit count: 207

Filed under:
|
|

I understand that it may be a rare situation for an executable to have spaces in it, but it could happen.

An example may be the best explanation..

Using standard tools, I want to determine the location (on the file system) of the executable which owns(?) the current window...

  1. get the current window ID ...(xdotool getactivewindow )
  2. use the ID to get the PID ...(wmctrl -p -l | sed ... ID ....
  3. use the PID to get the executable's name ... (ps -A ... here is where I run into problems !

Whith ps, when listing only the executable's name (-o ucmd), it truncates the name to 15 characters, so this rules out this option for any name which is longer.
Widening the column (-o ucmd:99 ) makes no difference.. If pgrep is anything to go by, its matching is limited to 15 because of stat (see: info pgrep)..

Listings in variants of "full" mode (eg -A w w) are not useful when the name concerned has spaces in it, because this name is separated from its args by another space!.. Also, in "full" mode, if the process was started by a link, the name of the link is shown, rather than the executable's name.

Is there some way to do this (using standard tools)? ...or are spaces a show stopper here?

© Ask Ubuntu or respective owner

Related posts about bash

Related posts about process