From: SMTP%"MACRO32%WKUVX1.BITNET@ULKYVM.LOUISVILLE.EDU" 14-MAY-1993 09:48:59.36 To: EVERHART CC: Subj: Re: Background Process X-ListName: "VMS Internals, MACRO, & BLISS Discussions" Warnings-To: <> Errors-To: MacroMan@WKUVX1.BITNET Sender: MacroMan%WKUVX1.BITNET@ULKYVM.LOUISVILLE.EDU X-Newsgroups: vmsnet.internals Subject: Re: Background Process Message-ID: <1993May15.003711.2292@zl2tnm.gen.nz> From: don%zl2tnm.gen.nz@ULKYVM.LOUISVILLE.EDU Reply-To: MACRO32%WKUVX1.BITNET@ULKYVM.LOUISVILLE.EDU Date: 15 May 93 00:37:11 +1300 Organization: The Wolery Lines: 52 To: MACRO32@WKUVX1.BITNET X-Gateway-Source-Info: USENET In article <1993May12.185805.1@ducvax.auburn.edu>, johnd@ducvax.auburn.edu writes: > I'm having a little problem and was wondering if someone would point > me in the right direction. I'm trying to put a process in the > background. The clincher is that this C program has to initially > as for input, then become a background process. Is there a library > call that tells the system to take the current process and place > it in the background? I'm trying to avoid a fork() call at all cost. There is a hack that does work. It goes like this: Run your command as a DCL subprocess. The subprocess, when it decides to "background" itself, can then "detach" from DCL's "job control" facility. How? You spoof DCL so that the parent process thinks the subprocess has executed an "ATTACH" command to pass control back to the parent, and the subprocess doesn't and just keeps on going. The following DCL code demonstrates this. Run with "$ SPAWN @DETACH" (assuming you called the command file DETACH.COM). It's fairly easy to implement in a HLL (like Macro 8-) if you need a callable procedure. $ read SYS$COMMAND/prompt="Please enter something: " xyzzy $ write SYS$OUTPUT "I'll give you your tty back. See you in five secs." $ ! $ ! Get parent pid & process name $ ! $ parent = f$getjpi(0, "OWNER") $ parent_prcnam = f$getjpi(parent, "PRCNAM") $ ! $ ! Write parent process to mailbox. $ ! Parent writes record containing longword value SS$NORMAL (we hope!) $ ! $ open/read/write mbx DCL$ATTACH_'parent': $ write mbx parent_prcnam $ read mbx sts $ close mbx $ ! $ ! We're detached now. Wait a bit and prove it. $ ! $ wait 0:0:5 $ write SYS$OUTPUT "You entered: ", xyzzy, ". I'll go away now." $ exit I should of course point out that all this is highly undocumented and unsupported. It can also make things break if you don't hold your mouth right. (Try SPAWNing immediately after the procedure returns control, ie before it prints the "You entered..." line and exits.) Don Stokes, ZL2TNM (DS555) don@zl2tnm.gen.nz (home) Network Manager, Computing Services Centre don@vuw.ac.nz (work) Victoria University of Wellington, New Zealand +64-4-495-5052