An o2 sensor just measures the partial pressure of the oxygen in the gas its exposed to, determining how much o2 is in it. The signal is then fed to the ECU. The front O2 sensor (precat) is the one the ECU uses for determining how much fuel to add. The sensor has a very narrow range (as opposed to "wideband" sensors) and is most accurate right around stoich, or 14.7 parts air to 1 part fuel (14.7:1, or roughly the point where all o2 and all fuel is consumed). The ECU doesnt shoot right for 14.7 since it doesnt have that much control, instead it cycles up and down around 14.7, or about .5 volts on the sensor (it has a 0 to 1 volt range). The average of these cycles/fluctuations will be around .5 volts, or 14.7:1 under light load.
In order to keep the O2 sensor voltage cycling around stoich, the ECU will adjust its fuel trims. This is just a parameter the ECU can use to control fuel. There is a short term fuel trim (STFT) that adjusts constantly. The running average, or decaying average, of the STFT is then fed into the long term fuel trim value (LTFT) which changes much more slowly. It wont adjust until a few conditions are met. Car has been operating at steady state for some time (idling or cruising on the highway for example), up to temperature (this is why a bad coolant temp sensor will screw up your fuel mileage, choke will always be on), you are not trying to make some power (full throttle, climbing a hill, etc), etc. You'll hear people refering to trims when talking about dialing in bigger injectors with a fuel tuning device like the SAFC, emanage, DSMlink, etc. They arent used in full throttle (WOT) tuning though.
The o2 sensor is only used in closed loop operation, and not in open loop operation. Closed loop operation is just what it sounds like. There is a closed "loop" between the sensor, the ecu, and its output to the injectors, which is then seen by the sensor, and the loop continues. Its also known as a feedback loop. Open loop is the opposite. The ECU no longer cares what the O2 sensor reports back, so there is no feed back loop. The loop is "open" (like an electrical circuit). It uses mass airflow (flow speed, baro pressure, and temp (turbo cars), or MAP (manifold absolute pressure) combined with known intake volume etc in the non-turbo cars), and a few other parameters like rpm, to pull a number off of a lookup-table and inject that predetermined amount of fuel. This is why we use an SAFC or similar to intercept and alter the airflow reading sent to the ECU, to change how much fuel delivery we actually get, thereby changing our air:fuel ratio.
The second O2 sensor, post cat, is there just to verify that the cat works. The front O2 will see that cycling we talked about above around .5 volts. If the cat is there and working, it will be almost a flat line, or constant voltage, from the second sensor. The cat smooths out those fluctuations in the O2 content of the exhaust gas mixture since it uses it to burn up any unburned hydrocarbons. If the cat is not working, or we have removed it, the rear sensor will pick up exactly the same cycling/fluctuating voltage that the front sensor reports. Then the ECU will watch it for some time, and then say ok its not working or not there, heres a "catalyst system efficiency below threshold (bank 1)" DTC, or Diagnostic Trouble Code, hich will trigger a Check Engine Light. (not all DTCs trigger CELs).
This is specific to a turbo dSM, but it should hold true in all OBD2 equiped cars, or basically any car produced for the 96 model year and later. Some earlier cars, like the 95 DSMs had switched over earlier. Note that the 1g cars do not use the rear sensor, it wasnt a requirement for OBD1 or other proprietary systems, but is for the OBD2 protocall. This is a basic overview but should be complete enough to explain how the system essentially works.

Hope it helps.