Welcome!
Can I ad an external ssd disk and boot from that? Will that help? Is the usb Can I do something else?
The external SSD startup disk solution isn't applicable to your model of iMac (20-inch, Mid 2009) because it isn't equipped with USB 3.0 ports, only USB 2.0 ports.
However, I noticed that your Mac is running OS X Yosemite 10.10, while it supports OS X El Capitan 10.11. OS X El Capitan improves the stability, performance, and security of your Mac. You can get it here: How to download macOS - Apple Support.
Before installing, it’s a good idea to back up your Mac. While installing, avoid putting your Mac to sleep or closing its lid. Your Mac will restart, and it might show a progress bar or blank screen several times.
Additionally, on a previous generation Mac computer, such as yours, it may be a wise idea to run DriveDx. DriveDx can verify that your internal disk isn't failing.
Can I use the imac as a second screen to my macbook pro mid 2012
Yes; you can. From Use your iMac as a display with target display mode - Apple Support,
24-inch and 27-inch iMac models introduced in 2009 and 2010
To use any of these iMac models as an external display:
The iMac used as a display must have macOS High Sierra or earlier installed.
The other Mac that you're connecting it to must have been introduced in 2019 or earlier and have macOS Catalina or earlier installed.
The cable connecting the two Mac computers must be a Mini DisplayPort cable.
So, as long as you use a Mini DisplayPort cable, you can use your iMac as a larger display for your MacBook Pro (13-inch, Mid 2012). However, the cost of cabling isn't always worth it, and Target Display Mode won't work with newer Mac computers. A high-quality external display could potentially work easier than Target Display Mode, and continue to work with newer Mac computers.
Jack