Normally
DOS can run only one program at a time. When a program finishes, it returns control to DOS using the
system call of the
DOS API. The memory and system resources used are then marked as unused. This makes it impossible to restart parts of the program without having to reload it all. However, if a program ends with the system call or , the operating system does not reuse a certain specified part of its memory. The original call, , is called "terminate but stay resident", hence the name "TSR". Using this call, a program can make up to 64 KB of its memory resident. MS-DOS version 2.0 introduced an improved call, ('Keep Process'), which removed this limitation and let the program return an
exit code. Before making this call, the program can install one or several
interrupt handlers pointing into itself, so that it can be called again. Installing a hardware interrupt vector allows such a program to react to hardware events. Installing a software interrupt vector allows it to be called by the currently running program. Installing a timer interrupt handler allows a TSR to run periodically (using a
programmable interval timer). The typical method of using an interrupt vector involves reading its present value (the address), storing it within the memory space of the TSR, and replacing it with an address in its own code. The stored address is called from the TSR, in effect forming a singly linked list of
interrupt handlers, also called
interrupt service routines, or ISRs. This procedure of installing ISRs is called
chaining or
hooking an interrupt or an interrupt vector. TSRs can be loaded at any time; either during the DOS startup sequence (for example, from
AUTOEXEC.BAT), or at the user's request (for example,
Borland's
Sidekick and Turbo Debugger, Quicken's QuickPay, or FunStuff Software's Personal Calendar). Parts of DOS itself use this technique, especially in DOS versions 5.0 and later. For example, the
DOSKEY command-line editor and various other utilities are installed by running them at the command line (manually, or from
AUTOEXEC.BAT or through
INSTALL from within CONFIG.SYS) rather than loading them as device drivers through
DEVICE statements in CONFIG.SYS. Some TSRs have no way to unload themselves, so they will remain in memory until a reboot. However unloading is possible externally, using utilities like the
MARK.EXE/
RELEASE.EXE combo by
TurboPower Software or
soft reboot TSRs which will catch a specific key combination and release all TSRs loaded after them. As the chain of ISRs is singly linked, and a TSR may store the link to its predecessor anywhere it chooses, there is no general way for a TSR to remove itself from the chain. So usually a stub must be left in memory when unloading a TSR, causing memory fragmentation. This problem gave rise to TSR cooperation frameworks such as
TesSeRact and AMIS. Seeing a TSR inspired
Andy Hertzfeld to create
Switcher for
Classic MacOS.
Interrupt sharing To manage problems with many TSRs sharing the same interrupt, a method called Alternate Multiplex Interrupt Specification (AMIS) was proposed by
Ralf D. Brown as an improvement over previously used services offered via INT 2Fh. AMIS provides ways to share
software interrupts in a controlled manner. It is modeled after IBM's Interrupt Sharing Protocol, originally invented for sharing hardware interrupts of an x86 processor. AMIS services are available via Int 2Dh. The proposal never gained a widespread traction among programmers in its days. It existed alongside several other competing specifications of varying sophistication. ==Faults==