From: "Charles Sandmann" Newsgroups: comp.os.msdos.djgpp Subject: Re: How do I gracefully terminate my TSR application? Date: Sun, 14 Jun 1998 10:21:52 Organization: Aspen Technology, Inc. Lines: 21 Message-ID: <3583a440.sandmann@clio.rice.edu> References: <6m0oeu$c94 AT news3 DOT euro DOT net> Reply-To: sandmann AT clio DOT rice DOT edu NNTP-Posting-Host: dmcap2.aco.aspentech.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk > Q1) How can I compute the correct value to be passed in the DX register? > Currently I am passing 1000 paragraphs because this is more than enough, but > how can I compute the exact number? Does your TSR use the transfer buffer or any RTL routines which use the transfer buffer? If so, you need the size of the PSP plus the transfer buffer size you are using. > Q2) Now I want to implement a "quit" command, that will also reach the TSR > via the software interrupt handler. But how can my TSR terminate itself > gracefully? I have tried: For a DOS TSR to go away, you need to unhook all interrupts and deallocate the memory. Don't call 0x31 again, just free the DOS PSP and environment (cwsdpmi does this for it's own image). Unwinding the DPMI image is a more difficult - you need to do an exit() call which frees the DPMI memory, frees the selectors, etc. There must not be another DPMI image running "nested" under the TSR - the signal for it to exit must come from a real mode program. Reading the paragraph above - hummm - yes it's possible but very complicated. It may even be a bit different under different DPMI providers.