Exercise refers to slowly increasing your attributes over time by doing certain helpful things and avoiding certain other things.
Of the six attributes (strength, dexterity, constitution, intelligence, wisdom and charisma), you can only exercise four; there is no way to exercise intelligence or charisma. (Charisma can be increased by stepping into a magic trap, and intelligence by eating a mind flayer corpse or quaffing a blessed potion of enlightenment. All attributes can be raised by quaffing a potion of gain ability (best if blessed) or drinking from a magic fountain (best if your Luck is greater than 3)).
Here are examples of how to exercise strength, dexterity, constitution, and wisdom:
- Push boulders around for strength.
- Wield a blade and #force open locked chests for dexterity.
- Eat and avoid becoming hungry or satiated for constitution.
- Engrave Elbereth with uppercase "E" and lowercase "lbereth" for wisdom.
For a more complete list of exercise methods, see the attribute page.
Exercise does not cause immediate gains in your attributes. Instead, exercising an attribute has a chance of (18 - current attribute value) in 19 of incrementing the attribute's exercise counter, whose maximum value is 50.
NetHack does exercise checks at certain times. Upon a check, each counter is examined. If the corresponding attribute is already 18 or greater, nothing is done. Otherwise a random number between 0 and 49 inclusive is chosen. If it is greater than for a non-wisdom attribute or for wisdom, nothing is done. Otherwise, the attribute is changed by adding 1 if the counter was positive and subtracting 1 if it was negative, and the counter is set to zero. Afterwards, no matter what happened, the counter is halved, rounding down.  
The first check happens on turn 600. Subsequent checks occur at random intervals from 800 (inclusive) to 1000 (exclusive) turns from the last one. Upon loading a saved game, if the first check has happened, the next check is set to happen from 800 (inclusive) to 850 (exclusive) turns afterwards. Thus, surprisingly, saving and reloading the game can have an in-game effect on the player's attributes. It is not known whether any player has yet devised a method to exploit this. However, in Slash'EM Extended the attribute increase check time is saved to disk, so in that variant the save/load exploit cannot be performed; it works in other variants though.
Abuse is the opposite of exercise. Acts of abuse can undo exercise, or even cause your strength, dexterity, constitution or wisdom to drop. For a comprehensive list of abuse methods see the attributes page. If your stats get lowered, use a unicorn horn to heal any such loss. In UnNetHack and SporkHack, this won't work – use a potion or spell of restore ability, instead.
Each act of abuse has an exactly 50% chance of reducing the attribute's exercise counter by 1. 
- exercise in attrib.c
- exerchk in attrib.c
- attrib.c in NetHack 3.4.3, line 441
- reset_attribute_clock in attrib.c