What does this "... | ps `cat`" command do?

Solution 1:

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)