Engine knocking
Knocking or pinking or pre-ignition in internal combustion engines occurs when the fuel ignites before the optimum moment during the compression phase of the four-stroke cycle. The combustion occurs either spontaneously due to the heat created by compression, or by the spark occurring too early due to incorrectly set timing. The shockwave resulting collides with the rising piston creating the characteristic sound. Note that the fuel is normally ignited slightly before the point of maximum compression - this is to allow a small time for the flame-front of the burning fuel to expand throughout the mixture, so that maximum pressure occurs at the point of maximum compression. It is only when this flamefront arrives too early, for whatever reason, that the knocking effect occurs.
Knocking can typically be prevented by higher octane gasoline, reduction of in cylinder temperature (cooling or compression reduction), or the addition of "lead" or other anti-knock additives to the gasoline. Correct ignition timing is also essential for optimum anti-knock performance (and efficiency). Modern car engines have "anti knock" sensors that detect knock and slow the spark timing to prevent knock, allowing the car to use gasoline of varying octane ratings.
To the driver, knocking can be detected as "knocking" or "pinking" noise during acceleration.