To use a 27-inch iMac in Target Display mode with another computer as the source:
Make sure both computers are turned on and awake.
Connect a male-to-male Mini DisplayPort cable to the Mini DisplayPort on each computer. The 27-inch iMac will enter Target Display Mode and display content from the source computer.
Note: If you are connecting two 27-inch iMacs, connect a Mini DisplayPort cable to each computer and press Command + F2 on the 27-inch iMac keyboard that you will use as an external display.
To leave Target Display mode, press Command + F2 on the keyboard of the 27-inch iMac that is in Target Display mode. To return to Target Display mode, press Command + F2 again.