Of course, the emissions control system has lots of sensors and parts that try to make sure that the engine runs `efficiently'. That is, you want it to burn all the gasoline and put out just plain CO2 + H2O, not any of those nasty acid-rain components (sulfur and nitrogen oxides), no ozone, no smog components (unburnt hydrocarbons), etc. To do its job, all those sensors have to be working properly. The gas cap is also part of the emissions control system, because if the gas cap is loose or missing, gasoline can evaporate right from the tank, putting lots of completely unburnt hydrocarbons in the air.
Now, when you take your car in for a smog check, it might need to be inspected by a poor minimum-wage slob who once had 30 minutes of instruction to use some government-mandated bit of emissions-testing equipment, and that is about it. So, in order to get their money's worth from this guy, the government folks figured: why not have each car diagnose itself? They can tell the guy: `You must look at the check engine light. If it is on, the car fails.' Then they just have to make sure that the light catches most emissions problems.
To catch such problems, the light will come on if a sensor glitches. It will then stay on unless and until it is (a) reset by someone using appropriate equipment, or (b) the glitch goes away and stays away through some minimum number of self-test cycles. (The OBD-II computer supposedly also remembers whether all those tests have passed, so if they choose, your government can have the testing guy see if you have recently had the light turned off manually.)
The exact details of the self-tests that have to pass to clear any current `check' condition are either some big secret, or just not well known. Or at least, I have not found a list of them anywhere. They appear to include some minimum number of cold starts, warm starts, travel at low speeds, travel at high speeds, etc. For all I know you have to turn the radio off and on too. Seriously, though, if all is well -- such as, if the gas cap was loose and is now tight -- there is some set of conditions after which OBD-II will have passed its required `all is well' tests and the light will go out again.
UNFORTUNATELY, given the one `something is wrong' light, everyone also uses it for more serious problems than `some sensor glitched for a moment' or `your gas cap is loose'. So the Right Thing To Do, when you have a check engine light, is to hook it up to a Check Engine Light Reader immediately and find out why the light is on. The `reason' is a code indicating some part(s) giving back `funny readings', i.e., the engine computer's equivalent of `there's a funny noise coming from over there, kind of a squeeka-squeeka-clicka, when it's supposed to be a clicka-squeeka-plink!' Once you have read out the `reason', you can reset it, and see if the problem is still there, and you can decide how serious it is and how soon you want to take care of it.
Note that while the `reason' (or code) is highly specific, you should always take anything a computer says with a grain of salt. Just because it (say) claims that you have an injector circuit malfunction (code `P0200') does not mean that you actually have one. Maybe instead the wires that come back from the injector sensors are loose, for instance. The computer can only tell you what it `hears', and if one of its inputs is broken, its diagnosis can be completely wrong.
You can find a list of OBD-II codes here. There are some portable readers you can buy for home use, although they are all kind of expensive, or you can just take it in to a shop that has the right kind of reader. Although OBD-II is `standard', the connectors are not, so you have to get one works with your particular car.
I have not (yet) bought any scanners, but have found these two available: AutoXray, Actron. Anyone with any particular experience (or other links), let me know.