7.8 Terminate-and-Stay-Resident Programs

When a terminate-and-stay-resident program (often called a TSR) returns control to its parent program, its code and data remain in memory to be used by other programs.

There are three types of terminate-and-stay-resident programs:

Service programs. These provide useful functions for other programs. For example, PRINT.EXE is a TSR that maintains the print queue and provides functions that other programs can use to examine the queue and add files to it. Service programs install an interrupt handler before terminating. Subsequent programs then use the corresponding interrupt, much as they use MS-DOS System Function (Interrupt 21h), to call the service program's functions.

Pop-up programs. These monitor the keyboard and resume executing upon receiving particular keystrokes. To monitor the keyboard, a pop-up program intercepts an interrupt associated with the keyboard or with a key combination, such as SHIFT+PRINT SCREEN or CTRL+BREAK.

Hardware-support programs. These operate much like low-level device drivers, controlling the operation of specific devices while providing functions that permit other programs to access the device.

A terminate-and-stay-resident program consists of at least two parts: an initialization routine and one or more interrupt handlers. The initialization routine is generally the same for all programs. The interrupt handlers depend largely on the program type, although they may carry out the same housekeeping tasks and are installed by using the same procedure.