If its an iMac g3 stick a flattened paper-clip in the little hole in the slot for the CD to Eject immediately.
If its an iMac Intel, type this in Script Editor do shell script "drutil tray eject"
if it aint responding (as in frozen entirely), shut it down via Power Button and reboot, While the BONNNNNNG sounds, look at your keyboard, the Green Caps Lock light flashes on...immediately hold Option. After 35 seconds (as there is a CD in) It will show boot manager.
Then
Hold Eject until it pops out works everytime.
cheers!
allbrokeup
Hold the Eject button.