| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Timing out a REXX program |
Hello Mike! Saturday April 06 1996 19:01, Mike Bilow wrote to All: MB> I have a situation in which I want to run a REXX script periodically, but MB> with the ability to time out if something goes wrong. For example, I have MB> a program (BinkleyTerm) which is started from a batch file and which MB> is usually running, but which exits with certain errorlevels at MB> scheduled times. One of these errorlevels causes the parent batch file to MB> run a particular REXX script. Because there are certain real-time MB> constraints, I need to be able to limit the amount of time that the REXX MB> script runs, killing it ungracefully if necessary as a last ditch effort to MB> keep the system running. I spent a few hours learning rexx to solve this. (Thank's for the excuse, I've been meaning to get around to it for awhile :-) MB> If the program in question was an EXE rather than a REXX script, then MB> I MB> could use something like DosKillProcess(). But this does not work because MB> simply killing the REXX script process has the effect of killing the parent MB> batch, too, since CMD itself is the process. I looked first as DosSendSignalException() but rexx doesn't use signal's to handle ctrl-c AFAICT. MB> The ideal approach to doing a time out would be to build it directly MB> into MB> the program, which would naturally be accomplished by multithreading. MB> However, there is no way to multithread a REXX program, as far as I know. Here is where you go astray! I fooled around with some functions and came up with a multithreaded rexx program (ok, it does use some c functions) MB> The second approach is to devise some sort of REXX DLL which the REXX MB> script could use to set a time out on itself. The problem here is again MB> that the DLL would only be able to kill the REXX process, which is really MB> that of the parent batch. I would think that there is some way to do this, MB> since hitting Ctrl-Break during a REXX script will terminate it MB> without terminating the parent batch, but I am not sure exactly how to make MB> that distinction. It's sorta like this idea. I've setup 4 rexx functions, it could be done in two however. GetPID() - just returns the process id GetTID() - same for the thread id TimeOut(PID, TID, milliseconds) - sets up the thread and starts it CancelTimeOut(PID,TID) - posts the event semaphore RexxTimeoutThread(ULONG) - does the dirty work What basically happens is you call TimeOut() with the relevant data. It starts the thread which in turn creates an event semaphore derived from the pid & tid. It then blocks on the semaphore until either you call CancelTimeOut() or it times out. In the event of it timing out, it calls the rexx function RexxSetHalt() which sends a halt to the rexx interpreter. In your rexx script, you set in to jump to a label on reciept of a halt and volia! you even get to do cleanup . The source is pretty messy as I was mostly just experimenting but it should be understandable. I think it's even pretty portable as I tried to stick to OS/2 API's. There are 5 files, test.cpp :source test.h :header test.def :just has 'LIBRARY TEST' test1.cmd :parent rexx script test2.cmd :child rexx script I'll post them in the next few messages. Doug --- GoldED/2 2.50+* Origin: Realm of the Dragons - `Where thy mind hath no limits' (1:250/516) SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809 @PATH: 250/516 101 99 3615/50 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.