It varies according to the mechanical standards used by the owner of the locomotive.
On newer locomotives (since 2000), there is a great reliance on electronics, and it's almost universal that there is an electronic alertness device ("alertor") which times intervals that become shorter as speed increases. If the Engineer performs certain actions during the interval, the alertor is re-set and begins another interval. Typically, throttle/dynamic brake controller movement; applying, releasing, or actuating the air brakes; sounding the whistle; or ringing the bell would re-set the interval timer of the alertor. Additionally, there is a button on the control stand, usually with a large mushroom-shaped cap, which the Engineer can press (or, if in Texas "mash") to reset the alertor interval. If none of the required actions occurs and re-sets the alertor, a light inside the cab begins to flash rapidly. If that does not elicit a response from the Engineer, then an annoying audible alarm begins to sound. If there is still no response from the Engineer, the alertor initiates a penalty air brake application and opens the pneumatic control ("PC") switch, which causes the locomotive to go to idle and stop pulling the train. The penalty air brake application is not an Emergency brake application. It is a service (normal braking) application that continues to gradually increase until the maximum normal braking is reached. After the train has stopped, the Engineer can use the automatic brake valve to release the brakes and then can proceed. The event recorder records all of this, and, in some cases, intentionally flags this as an unacceptable practice, calling the attention of management to its need to investigate the cause. The normal discovery process is that, electronic event recorder data is downloaded by radio at locations where the train is inspected and the locomotive is fueled. The event recorder sends an electronic copy to a computer data base, where the raw data is processed and that is when the penalty brake application is discovered and the appropriate supervisors are informed. This catches habitual dozers in the act and enables remedial action to be taken. Even routine examination of event recorder charts shows when the Engineer uses the mushroom button. I had certain Engineers on my territory who used the mushroom button more than was typical, and I made it a point to ride more frequently with them, and to check on them by visiting with Conductors who would tell me the truth. They will cover up for an Engineer who occasionally comes to work tired or impaired, but they get tired of working with Engineers whom they have to watch closely, and they'll confide in an official they can trust.
Alertors are designed to detect most attempts to defeat them by artificial means. Norfolk & Western used its own type of alertor which had a pencil-sized long coil spring that extended from the control stand and could be swatted to re-set the alert interval. Some Engineers would take a piece of train order string and tie it to the tip of the spring, run it up over the sun visor bracket and tie the other end to the Sprague Air-Push windshield wiper motor's hand operation lever, and then turn on the windshield wiper. Eventually, alertors were modified so that constant acknowledgement or acknowledgement at a steady interval would not re-set the alert interval. All newer locomotives have an electronic audible device. Many older locomotives, which relied on a very loud air whistle as the alert of last resort, have been modified so that the whistle is not in an accessible location, thereby defeating attempts to reduce its volume by muting it with rags.
Older locomotives might be equipped with less electronically sophisticated alertors -- some dating back to the l1960's -- and there are probably a few dead man pedals still in use, but I would personally doubt that there is a "one-owner" locomotive on a major railroad still equipped with one. (That's just a guess.) The dead man pedal can be held in the depressed position by wedging a flag stick between it and some part of the control stand, or by placing a brake shoe on top of it. That was almost universal practice when I was an Engineer, except on passenger trains, where the dead man pedal was almost universally depressed by foot, as intended.
Engines designed for switching service are often not equipped with alertness devices.