If your gas stove, water heater or room heater has a standing pilot -- which is a pilot light that stays lit when the burner isn't on -- it has a thermocouple; this is a heat-sensitive device that generates an electric current to keep the gas valve open. It's there as a safety measure; when the pilot goes out, the thermocouple shuts off the valve to prevent gas leakage and avert a potential explosion or fire. Thermocouples wear out and are easy to replace, but you should test yours before replacing it. It may be installed improperly, or something else may be wrong.
A Preliminary Test
The definitive way to determine whether a thermocouple is defective is to test it with a voltmeter. A simple procedure can tell you whether that test is necessary.
Turn the gas control to "Pilot" and push in the control knob while you light the pilot. If the appliance has an electronic spark ignitor, push the red button repeatedly until the pilot lights. Otherwise, light the pilot with a long match.
Hold in the knob for 60 seconds, ensuring the pilot stays lit during this time, then release it. If the pilot goes out, that's the sign of a bad thermocouple, but there's one more thing to check.
Light the pilot again and look at the tip of the thermocouple. It should be no farther from the flame than 1 inch, but it may have been displaced for some reason. If it's too far away, reach in and push it closer to the pilot, then try the pilot test again. If the pilot still goes out, test the thermocouple with a voltmeter.
Testing with a Voltmeter
Unscrew the thermocouple from the gas valve, using a 7/16-inch wrench. If you have one, screw a test adapter into the valve and screw the thermocouple into the adapter. The adapter gives you an easy way to secure the meter lead to the thermocouple. Without it, your leads should have alligator clips -- otherwise you need a helper. If you don't have an adapter, leave the thermocouple detached from the gas valve.
Attach the black lead of a multimeter set to measure millivolts to the adapter or to the soldered end of the thermocouple, using an alligator clip. Attach the red lead to the copper tube that leads to the tip.
Light the pilot and let it burn for 45 seconds. At this point, you should get a reading from 6 to 12 millivolts on the meter. If not, the thermocouple is bad and needs replacing.