All Topics  
Terminate and Stay Resident

 

   Email Print
   Bookmark   Link






 

Terminate and Stay Resident



 
 
Terminate and Stay Resident (TSR) is a computer system call
System call

In computing, a system call is the mechanism used by an application program to request service from the kernel based on the Monolithic_kernel or to system servers on operating systems based on the microkernel-structure....
 in DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
  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
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
, by transferring control back to the terminated program on automatic or externally-generated events, such as pressing a certain key on the keyboard
Keyboard

Keyboard may refer to:* Alphanumeric keyboard* Keyboard , a set of alphanumeric and command keys used to input information to a computer* Musical keyboard, a set of adjacent keys or levers used to play a musical instrument...
. Some TSR programs are effectively device driver
Device driver

In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....
s for hardware
Computer hardware

A personal computer is made up of computer hardware, multiple physical components onto which can be loaded into a multitude of software that perform the functions of the computer....
 not directly supported by the operating system, while others are small utility programs offering frequently-used functionality such as scheduling and contact directories.

ally, in the DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 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
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
's shell program, COMMAND.COM
COMMAND.COM

COMMAND.COM is the filename of the default operating system Shell for DOS operating systems and the default command line interpreter on 16/32-bit versions of Microsoft Windows ....
, using the system call
System call

In computing, a system call is the mechanism used by an application program to request service from the kernel based on the Monolithic_kernel or to system servers on operating systems based on the microkernel-structure....
 INT 21H/4CH.






Discussion
Ask a question about 'Terminate and Stay Resident'
Start a new discussion about 'Terminate and Stay Resident'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Terminate and Stay Resident (TSR) is a computer system call
System call

In computing, a system call is the mechanism used by an application program to request service from the kernel based on the Monolithic_kernel or to system servers on operating systems based on the microkernel-structure....
 in DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
  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
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
, by transferring control back to the terminated program on automatic or externally-generated events, such as pressing a certain key on the keyboard
Keyboard

Keyboard may refer to:* Alphanumeric keyboard* Keyboard , a set of alphanumeric and command keys used to input information to a computer* Musical keyboard, a set of adjacent keys or levers used to play a musical instrument...
. Some TSR programs are effectively device driver
Device driver

In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....
s for hardware
Computer hardware

A personal computer is made up of computer hardware, multiple physical components onto which can be loaded into a multitude of software that perform the functions of the computer....
 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 DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 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
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
's shell program, COMMAND.COM
COMMAND.COM

COMMAND.COM is the filename of the default operating system Shell for DOS operating systems and the default command line interpreter on 16/32-bit versions of Microsoft Windows ....
, using the system call
System call

In computing, a system call is the mechanism used by an application program to request service from the kernel based on the Monolithic_kernel or to system servers on operating systems based on the microkernel-structure....
 INT 21H/4CH. 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 only up to 64KB of its memory resident. MS-DOS version 2.0 introduced an improved call, INT 21H/31H ('Keep Process'), which removed this limitation and also let the program return an exit code. Before making this call, the program can install one or several interrupt
Interrupt

In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
 vectors pointing into itself, so that it can be called again. Installing a hardware interrupt vector allows such a program to react to hardware events; a software interrupt vector allows it to be called by the currently running program; using a timer interrupt allowed a TSR to be summoned periodically.

By chaining the interrupt vectors TSR programs could take complete control of the computer. A TSR could have one of two behaviours:
  • Take complete control of an interrupt by not calling other TSRs that had previously altered the same interrupt vector.
  • Cascade with other TSRs by calling the old interrupt vector. This could be done before or after they executed their actual code. This way TSRs could form a chain of programs where each one calls the next one.


The 'Terminate and Stay Resident' method was used by most MS-DOS viruses
Computer virus

A computer virus is a computer program that can copy itself and infect a computer without the permission or knowledge of the user. The term "virus" is also commonly but erroneously used to refer to other types of malware, adware and spyware programs that do not have the reproductive ability....
 which could either take control of the PC or stay at the background. Viruses would react on disk I/O or execution events by infecting executable (.EXE or .COM) files when they were run and data files when they were opened.

Parts of DOS itself, especially in DOS versions 5.0 and later, used this same technique to perform useful functions, such as the DOSKEY command-line editor and various other installable utilities which were installed by running them at the command line (manually or from AUTOEXEC.BAT) rather than as drivers through CONFIG.SYS.

A TSR program can be loaded at any time; sometimes, they are loaded immediately after the operating system's boot, by being explicitly loaded in the AUTOEXEC.BAT
AUTOEXEC.BAT

AUTOEXEC.BAT is a system file found originally on the MS-DOS operating system. It is a plain-text DOS batch file that is located in the root directory of the boot device....
 batch program, or alternatively at the user's request (for example, Borland
Borland

Borland Software Corporation is a Computer software company headquartered in Austin, Texas. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn....
's SideKick
Sidekick

A sidekick is a stock character, a close companion who assists a partner in a superior position. Don Quixote's Sancho Panza, Sherlock Holmes' Doctor Watson, and Batman's companion Robin are some well-known sidekicks in fiction....
 and Turbo Debugger). These programs will, as 'TSR' implies, stay resident in memory while other programs are executing. Most of them do not have an option for unloading themselves from memory, so calling TSR means the program 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.

Faults

While very useful, or even essential to overcome DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
's limitations, TSR programs had a reputation as troublemakers. Many of the programs effectively hijacked the operating system in varying, documented or undocumented ways, often causing systems to crash on their activation or deactivation when used with particular application programs or other TSRs. As explained above, some viruses
Computer virus

A computer virus is a computer program that can copy itself and infect a computer without the permission or knowledge of the user. The term "virus" is also commonly but erroneously used to refer to other types of malware, adware and spyware programs that do not have the reproductive ability....
 were coded as TSRs, and were deliberately troublesome. Additionally, all program code in DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 systems, even those with large amounts of physical RAM, had to be loaded into the first 640 KB
Kilobyte

Kilobyte is a unit of Computer data storage equal to either 1,024 bytes or 1,000 bytes , depending on context.It is abbreviated in a number of ways: KB, kB, K and Kbyte....
 of RAM (the conventional memory
Conventional memory

In computing, conventional memory is the first 640 kilobytes of the memory on IBM PC compatible systems....
). TSRs were no exception, and took chunks from that 640 KB that were thus unavailable to application programs. This meant that writing a TSR was a challenge of achieving the smallest possible size for it, and checking it for compatibility with a lot of software products from different vendors—often a very frustrating task.

In the late 1980s and early 1990s, many video games on the PC platform pushed up against this limit and left less and less space for TSRs—even essential ones like CD-ROM
CD-ROM

CD-ROM is a pre-pressed Compact Disc that contains Computer data storage accessible to, but not writable by, a computer. While the Compact Disc format was originally designed for music storage and playback, the 1985 Yellow Book standard developed by Sony and Philips adapted the format to hold any form of Binary file....
 drivers—and arranging things so that there was enough free RAM to run the games, while keeping the necessary TSRs present, became a black art. Many gamers had several boot disk
Boot disk

A boot disk is a removable digital data storage medium from which a computer can load and run an operating system or utility program. The computer must have a built-in program which will load and execute a program from a boot disk meeting certain standards....
s with different configurations for different games. In the mid- to later 1990s, while many games were still written for DOS, the 640K limit was eventually overcome by putting parts of the game's data and/or program code above the first 1 MB of memory and using the code below 640K to access the extended memory (using extra-DOSian methods), with code being swapped into the lowest 1 MB of RAM as overlays. Because programming with many overlays is a black art in itself, once the program was too big to fit entirely into about 512 KB, use of extended memory was almost always done using a third-party DOS extender implementing VPCI or DPMI, because it becomes much easier and faster to access memory above the 1 MB boundary, and possible to run code in that area, when the x86 processor is switched from real mode to protected mode. However, since DOS and all DOS programs run in real mode (VPCI or DPMI makes a protected mode program look like a real mode program to DOS and the rest of the system by switching back and forth between the two modes), DOS TSRs and device drivers also run in real mode, and so any time one gets control, the "DOS extender" has to switch back to real mode until it relinquishes control, incurring a time penalty.

Return

With the arrival of expanded memory
Expanded memory

In computing, expanded memory is a system of bank switching introduced around 1984 that provided additional memory to MS-DOS programs that required more than what was available in conventional memory....
 boards and especially of Intel 80386
Intel 80386

The Intel 80386, otherwise known as the i386 or just 386, is a microprocessor which has been used as the central processing unit of many personal computers and workstations since 1986....
 processors in the second half of the 1980s, it became possible to use memory above 640 KB to load TSRs. This required complex software solutions, named Expanded Memory Managers, but provided some additional breathing room for several years. Famous memory managers are QRAM and QEMM
QEMM

Quarterdeck Expanded Memory Manager , is a memory manager produced by Quarterdeck Office Systems in the late 1980s through late 1990s. It was the most popular memory manager for the MS-DOS and other DOS operating systems....
 by Quarterdeck
Quarterdeck

Quarterdeck may refer to*A part of a ship. See Deck *Quarterdeck Office Systems...
, 386Max
386MAX

386MAX was a computer memory manager for DOS-based personal computers. It competed with Quarterdeck's QEMM memory manager. It was manufactured by Qualitas....
 by Qualitas, CEMM
CEMM

CEMM, for Compaq Expanded Memory Manager was probably the first so-called PC "memory manager" for Intel 80386 CPUs, able to transform extended memory into "EMS" expanded memory by using the virtual memory features and the virtual 8086 mode of the CPU....
 by Compaq
Compaq

Compaq Computer Corporation was an United States personal computer company founded in 1982, and is now a brand name of Hewlett-Packard Company....
 and later EMM386
EMM386

The name EMM386 was used for the expanded memory managers of both Microsoft's MS-DOS and Digital Research's DR-DOS, which created expanded memory using extended memory on Intel 80386 CPUs....
 by Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
. The memory areas usable for loading TSRs above 640 KB is called "Upper Memory Blocks
Upper Memory Area

The Upper Memory Area is a design feature of IBM IBM PC compatible x86 computers that was responsible for the Conventional memory#640 KB barrier....
" (UMBs) and loading programs into them is called loading high. Later, memory managers started including programs which would try to automatically determine how to best allocate TSRs between low and high memory (Quarterdeck's Optimize or Microsoft's MemMaker
List of DOS commands

A partial list of the most common Command s for DOS follows.In versions 5 of DOS and later, the user can get help by typing help at the shell prompt....
) in order to try and maximize the available space in the first 640 KB.

Decline

With the development of games using DOS extender
DOS extender

Developed in the 1980s to cope with the memory limitations of MS-DOS and its derivatives, DOS extenders are programs which enable software to run under the protected mode environment initially introduced with the Intel 80286 processor and later expanded upon with the Intel 80386, even if the host operating system is only capable of operating...
s (a notable early example was Doom) which bypassed the 640 KB barrier, many of the issues relating to TSRs disappeared, and with the widespread adoption of Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 and especially Windows 95 (followed by Windows 98) — which rendered most TSRs unnecessary and some TSRs incompatible — the TSR faded into the background, though Win16 applications could do TSR-like tricks such as patching the IDT
Interrupt descriptor table

The Interrupt Descriptor Table is a data structure used by the x86 architecture to implement an interrupt vector table. The IDT is used by the processor to determine the correct response to interrupts and exceptions....
 because real-mode Windows allowed it. The TSR has now almost disappeared completely, as multitasking operating systems such as Windows XP
Windows XP

Windows XP is a line of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptop, and media centers....
, Mac OS X
Mac OS X

Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
, and Linux
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
 provide the facilities for multiple programs and device drivers to run simultaneously without the need for special programming tricks, and the modern notion of protected memory makes the kernel and its modules exclusively responsible for modifying an interrupt
Interrupt

In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
 table.

Macintosh

Completely different in implementation, however similar in purpose, was Macintosh Desk Accessories. Early Macintosh operating systems were single-tasking, similar to MS-DOS, and to work around that limitation, Apple created Desk Accessories, available from the Apple menu, small programs that can be run within any currently running application, such as a Calculator. Third party companies wrote full-fledged Applications in the DA format, such as Paint programs for the ability to create a graphic for a word processor document without leaving the word processing program, effectively multi-tasking.

See also


  • Daemon
    Daemon (computer software)

    In Unix and other computer computer multitasking operating systems, a daemon is a computer program that runs in the background , rather than under the direct control of a user; they are usually initiated as background Computer processes....
     (Unix)
  • Windows service
    Windows Service

    On Microsoft Windows operating systems, a Windows service is a long-running executable that performs specific functions and which is designed not to require user intervention....


External links