On my Internet research, I found the following command as solution to find the process name of a window:

xprop _NET_WM_PID | sed 's/_NET_WM_PID(CARDINAL) = //' | ps `cat`

I just do not understand what happens here after the first |.

Let's assume that xprop _NET_WM_PID outputs 1000 as process ID. What happens next? Why do we have a cat after ps? I am a bit confused.


xprop ... | sed ... is executed first, then cat reads its output. Due to the use of backticks, the output of cat is substituted in ps `cat` such that the command becomes ps 1000.

An alternative command that leads to the same result is:

ps $(xprop _NET_WM_PID | cut -d= -f2)

This works as follows:

  1. Execute xprop _NET_WM_PID to retrieve the process ID of a window. After clicking a window, it outputs something like:

    _NET_WM_PID(CARDINAL) = 12345
  2. Split at the = and take the second field. cut -d= -f2 takes the _NET_WM_PID(CARDINAL) = 12345 string from standard input and writes 12345 to standard output.
  3. Finally run the ps command with $(...) substituted for the output of ..., the command that gets executed is ps 12345. (side note: `...` can also be used instead of $(...), though there are some differences)
  • 4
    Interesting "complexion", this | command 'cat' (I can't embed backticks in the backtick in comments?) ... the usual way is : | xargs command (with additionnal parameters to xargs, for example to limit to 1 or n arguments, etc) Apr 18 '13 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.