2009 iMac just uses DisplayPort. When you press Command-F2 on the iMac, it switches the DisplayPort input of its display from the DisplayPort output of the GPU to the external DisplayPort port. Then the other Mac can see the iMac's display as a newly connected DisplayPort display and will use it automatically.Wondering if this works with a later iMac. He used a 2009 iMac and he put a custom light weight Tiny Core Linux on a USB stick and booted from there to put the iMac in TDM as a second wired display.
Later iMacs use Thunderbolt 1 or Thunderbolt 2 which requires more work to enable Thunderbolt Target Display Mode. When you press Command-F2 on the iMac, it switches the DisplayPort input of its display from the DisplayPort output of its GPU to the DisplayPort output adapter of its Thunderbolt controller. It probably communicates with the other Mac over the Thunderbolt connection telling the other Mac to setup a Thunderbolt cross-domain DisplayPort tunnelling path between the DisplayPort input adapter of the other Mac's Thunderbolt controller to the DisplayPort output adapter of the iMac's Thunderbolt controller. Then the other Mac can see the iMac's display as a newly connected DisplayPort display and will use it automatically.
Other Macs do not have Thunderbolt controllers with a DisplayPort output adapter. They just have DisplayPort input adapters which are used to tunnel DisplayPort to DisplayPort output adapters of downstream Thunderbolt controllers.
Maybe someone could add this Thunderbolt cross-domain DisplayPort tunnelling path setup capability to Linux (if its not already there)? One could then use a Thunderbolt dock as a KVM switch: connect the dock to two PCs and have the tunnels to a connected display switch between the PCs. Also, the PCIe tunnels could be switched for the connected keyboard/mouse - it's a bit more clunky than a real KVM which might emulate a connected keyboard/mouse so that they don't appear to be disconnected when switching.