Function 31h Keep Program
Ends the current program by returning control to its parent
program but leaves (keeps) the program in memory and preserves the
program's resources, such as open files and allocated memory.
Entry AH = 31h
AL = Return value
DX = Size of resident portion, in paragraphs
Return This function does not return
──────────────────────────────────────────────────────────────────
The return value may be retrieved by a parent process via function
4Dh, or tested by means of the errorlevel feature of DOS batch
processing. If the program terminates normally, the return value
should be 00h.
Function 31h carries out the following actions:
- Reallocates program memory to the amount specified by DX (min.
6 paragraphs). Program memory includes only the program segment
prefix (PSP) and program data and code. The reallocation does
not affect the program's environment block, nor does it affect
the memory allocated by the program after it was loaded.
- Flushes the file buffers but leaves files open. Any locked
regions in the open files remain locked.
- Restores interrupt 22h, 23h, and 24h vectors from the addresses
saved in the PSP.
- Transfers control to the address specified by offset 0Ah
(termination address) in the PSP.
──────────────────────────────────────────────────────────────────
Before calling Keep Program, the initialization routine of a
terminate-but-stay-resident (TSR) program should do the following:
- Close all unneeded files, including standard devices
- Free the environment block if it is not needed
- Free all memory not needed to support interrupt handlers