[comp.sys.ibm.pc] BACKGROUND PROCESSES UNDERS DOS

jordan@titn.TITN (Jordan Bortz) (07/06/87)

Hello - we have a background process under DOS, which:

	1)	Terminates And Stays Resident
	2)	Chains Off The Timer Interrupt To Run
	3)	Reads Info From A Modem Line And Writes It To Disk

We are having problems with 3) -- sometimes it works, sometimes it crashes.
We have tried looking at the DOS busy flag and appear to do the right thing,
but it still fails intermittantly.

Has anyone out there experienced this problem, and possibly know of a
solution???

Thanks in advance:

				Jordan

-- 
=============================================================================
Jordan Bortz	Higher Level Software 1085 Warfield Ave  Piedmont, CA   94611
(415) 268-8948	UUCP:	(decvax|ucbvax|ihnp4)!decwrl!sun!dlb!plx!titn!jordan
=============================================================================

maa@nbires.UUCP (Mark Armbrust) (07/09/87)

In article <176@titn.TITN> jordan@titn.TITN (Jordan Bortz) writes: 
>Hello - we have a background process under DOS, which: 
> 
>	1)	Terminates And Stays Resident
>	2)	Chains Off The Timer Interrupt To Run
>	3)	Reads Info From A Modem Line And Writes It To Disk
>
>We are having problems with 3) -- sometimes it works, sometimes it crashes.
>We have tried looking at the DOS busy flag and appear to do the right thing,
>but it still fails intermittantly.

If you are using MSDOS file I/O to write to the disk, you need to make sure
that your Process ID (PID) is the same for all MSDOS file calls.  There are
two undocumented MSDOS calls to support this.  [I found them by snooping in
DEBUG; sort of recursive debugging?]


Function 50h:  Set Process ID -- Set the PID for the executing process.

	mov	bx, NEW_PID
	mov	ah, 50h
	int	21h

Function 51h:  Get Process ID -- Get the PID of the executing process.

	mov	ah, 51h
	int	21h		; PID returned in BX

On MSDOS 2.11 and 3.2 [the only versions I use] the PID has the same value
as the Program Segment Prefix (PSP).

Microsoft added and documented Function 62h:  "Get PSP" in MSDOS 3.X.  I don't
know about other versions, but in 3.2 functions 51 and 62 execute the same
code.  [I guess MS did't want to admit that there really was an easy way for
a .EXE program to find its PSP.  Also, 3.X documented function 58h is available
in 2.11.  Ain't politics wonderful! 8-)# ]

The general idea is to swap to your PID, do the MSDOS operations, and then 
swap back to it PID of the interrupted process.

Hope this helps.

Mark Armbrust

dalegass@dalcsug.UUCP (07/13/87)

>Hello - we have a background process under DOS, which:
>
>	1)	Terminates And Stays Resident
>	2)	Chains Off The Timer Interrupt To Run
>	3)	Reads Info From A Modem Line And Writes It To Disk
>
>We are having problems with 3) -- sometimes it works, sometimes it crashes.
>We have tried looking at the DOS busy flag and appear to do the right thing,
>but it still fails intermittantly.
>
>Has anyone out there experienced this problem, and possibly know of a
>solution???
>
>Thanks in advance:
>
>			Jordan
>
>-- 
>=============================================================================
>Jordan Bortz	Higher Level Software 1085 Warfield Ave  Piedmont, CA   94611
>(415) 268-8948	UUCP:	(decvax|ucbvax|ihnp4)!decwrl!sun!dlb!plx!titn!jordan
>=============================================================================

I'm working on a very similar set of routines, that work off the timer
and RS232 routines.  I've got the following working:

  wait(x) - returns control to the foreground for the specified time
  dos()   - invokes DOS, possibly waiting for it to become free--
	    returning control to the foreground while waiting
  com_out()-sends a character to RS232, returns control to the foreground
	    until finished being sent

  com_in() - returns a character from the RS232 buffer if there's
	     any there, or returns to the foreground until one is received.  
	     This is written but not debugged completely yet.  Stack
	     problems are giving me hassles, but I expect to have these
	     fixed in about a week.


One thing you may have missed when writing to files is the fact that file
pointers may not be preserved between background time slices.  I.E. You
should open a file, write to it, and close it, without giving any time
to the foreground process, or else you may lose your handle.

- dalegass@dalcsug.uucp