Funny you should ask right now. My personal answer to your question "how does a UPS work" is "extremely badly".
Now serious answers: Agree with most what was said above. I happen to use an APC UPS. Not because they are particularly great, but because about 10 or 15 years ago when my previous UPS died, I needed one urgent, and the local office supply store had a small APC UPS on sale for about $80, which is why I have that model. To answer your question of how to shut the computer down: I happen to use the apcupsd software mentioned above, which works really well for me, after considerably fighting to configure it correctly. I have tried installing nut, and after some back and forth and it being less than perfect, I went back to using apcupsd. Agree with gpw928 there. And finally, for normal households neither cooling nor big diesel generators are a real issue.
And as cracauer said: Configure the program that monitors the UPS to look at both remaining runtime AND battery charge. Don't let the battery discharge so far that after the power is restored, the battery is nearly empty. I have my UPS configured (theoretically, see below) to shut down at 50% battery charge OR when the remaining run time is less than a few minutes (it takes less than 30 seconds to do a clean shutdown of my server). At 50% battery charge, I have more than a few minutes, so I'm safe.
Here is our situation at home: My server (and the networking gear for it: WiFi hub, wired ethernet switch, and phone company DSL modem) are all on that cheap $80 UPS that is being monitored. In addition, we have an automatic propane-fueled generator, which automatically comes within 15-20 seconds (not minutes!) after a power outage. We shut the generator off at night, because when we're sleeping, we don't need lights or computers, the refrigerator makes it through the night just fine, and we don't like the noise. Obviously, when we shut the generator off, we first turn the server (and its UPS) off. In addition, the pump/well control system (which runs on 24V DC internally) has an industrial UPS. Because it uses so little energy (about 8-10W) and that UPS has over 24 hours of run time, it is not even actively monitored (just has a low battery shutoff), since we'd always run the generator within a day. If we have long power outages (and in rainy/stormy winters, we sometimes have a week without electricity), we roll out a portable generator, and let the main generator stop twice a day, to check the oil and do regular maintenance on it (air filter cleaning, check spark plugs and valve lash, and so on).
So much for the theory. About two years ago, I replaced all three 12V batteries (one for the UPS in the house in the server, two for the 24V system for the pump control) with new ones. And Monday night we had moderate rain, and two 12-hour outages (with 4 hours of electricity in between). Problem 1: The Raspberry Pi in the pump control system didn't survive, lost its SD card. The weird part is that it shouldn't even have shut down or crashed, since it theoretically has 24 hours of battery backup. So much of last night and today was spent re-installing that (fortunately I had a spare card at home, and yes, I will look into industrial cards). Problem 2: After we came back up in the morning, I'm getting an e-mail every hour from apcupsd that my battery has died. I tested it this morning, and indeed, the battery in the UPS is so weak, I only have about 10 seconds (not minutes!) of UPS runtime. Problem 3: This made me suspect that something is wrong with my batteries, so I tested the 24V UPS for the water control. The news there is slightly better: About 2 hours of UPS run time, but it should be at least a whole day. So right now, I'm not happy with UPSes in general, and SD cards in particular. My wife brought home one UPS-size battery from the trash pile in her office (which is likely better than what I have at home), and tomorrow there will be a lot of time spent on battery testing and charging. I suspect that I'll find that the new-ish (2 year old?) batteries are trash, and I by mistake bought crap. And then I'll probably get three now Panasonic- or Yuasa-brand batteries for Christmas.
At least the reinstall of the Raspberry Pi is mostly done.