TSR type appls

David J. Hughes bambi at kirk.nmg.bu.oz
Tue Jul 3 03:41:40 AEST 1990


>From article <23762 at adm.BRL.MIL>, by ssds!clayc at uunet.uu.net (Clay Calhoun):
> I've a user here who wants to implement a "Terminate and Stay Resident"
> type application on a Unix box.  Here's the situation:
> 
>   1.  He has an "off-the-shelf" application that he's using.  No
>       source code available.  If his "chosen key sequence isn't
>       entered - then the input gets passed to the application and
>       the TSR continues to listen.
> 
>   2.  He wants to develop an application to run in the background,
>       capture his input - and perform "something" if a certain key
>       combination is received.
>   
> My dilema is, I'm not sure which application will be controlling the
> I/O.  If he starts his "TSR" and shoves it in the background - will
> it still have access to the I/O coming from the keyboard once he 
> starts the application he wants to use?

If the user always wishes to run these two programs together there is a
simple solution.  Let's say that the main application is app_A and the
"TSR" you mentioned is app_B.  App_B acts as a master to the execution
of app_A. The basic outline follows :-

	1. Upon execution of app_B, create a pipe and fork a child process.
	2. In the child process, dup2() the read end of the pipe 
		(pipe[0]) to be stdin.
	3. The child process now exec[l|v]'s app_A
	4. app_B now enters a read&write loop that is terminated if
		the child process app_A terminates (SIGCHLD).
	5. app_B just reads from stdin, has a look at the input,
		and either jumps into life if this is the desired
		input, or just passes it to the write end of the pipe
		(pipe[1]).
	6. app_A will just read from it's stdin (the pipe in this case)
		as it normally would, but will only receive the input
		that doesn't match the "TSR" magic string sequence.


In this approach, the "TSR" app_B, will control input for the duration
of the session of app_A.  The only thing to watch is that the magic
string (or HotKEY sequence for TSR people) is totally unique and that
it is not something that will be typed as a command or a response to the
main application (app_A).



Hope this helps.

bambi

+----------------------------------------------------------------------------+
| David J. Hughes   (AKA bambi)	 |   bambi at kowande.bu.oz.au                  |
| Systems Programmer		 |   bambi at kowande.bu.oz.au@uunet.uu.net     |
| Network Management Group       |   ..!uunet!munnari!kowande.bu.oz.au!bambi |
| Bond University, Gold Coast    |   Phone : +61 75 951111                   |
| Queensland,  Australia  4229   |   Fax :   +61 75 951456                   |
+----------------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list