Terminate and Stay Resident

related topics
{system, computer, user}
{math, number, function}
{game, team, player}
{area, community, home}
{school, student, university}
{ship, engine, design}

Terminate and Stay Resident (TSR) is a computer system call in DOS computer operating systems that returns control to the system as if the program has quit, but keeps the program in memory. Many software vendors use the call to create the appearance of multitasking, by transferring control back to the terminated program on automatic or externally-generated events, such as pressing a certain key on the keyboard. Some TSR programs are effectively device drivers for hardware not directly supported by the operating system, while others are small utility programs offering frequently-used functionality such as scheduling and contact directories.


Brief history

Normally in the MS-DOS operating system, only one program can be running at any given time and when it wants to stop running it relinquishes the control to DOS's shell program, COMMAND.COM, using the system call INT 21H/4CH[1]. The memory and system resources used by the program are marked as unused, effectively making it impossible to summon parts of it again without reloading it from scratch. However, if a program ended with the system call INT 27H or INT 21H/31H, the operating system does not reuse a certain specified part of the program's memory.

Using TSR

The original call, INT 27H, is called 'terminate but stay resident', hence the name 'TSR'. Using this call, a program can make up to 64KB of its memory resident. MS-DOS version 2.0 introduced an improved call, INT 21H/function 31H ('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 (see ISA and programmable interval timer, especially the section "IBM PC compatible").

The typical method of utilizing an interrupt vector involves reading its present value (the address), storing it within the memory space of the TSR, and installing a pointer to its own code. The stored address is called after the TSR has received the interrupt and has finished its processing, 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.

Full article ▸

related documents
IBM AIX (operating system)
Symmetric multiprocessing
Desktop environment
Amiga 600
Revision control
Ethernet over twisted pair
Video Graphics Array
Slow-scan television
Hercules Graphics Card
Digital Video Broadcasting
Digital Audio Tape
General Packet Radio Service
Time division multiple access
Virtual LAN
Load balancing (computing)
Data Link Layer
IBM System/370
File server
Computer networking
Gigabit Ethernet
LAN switching
Personal digital assistant
Video CD
Data compression
Computer display standard