P From:	SMTP%"MACRO32%WKUVX1.BITNET@ULKYVM.LOUISVILLE.EDU" 14-MAY-1993 09:48:59.36 To:	EVERHART CC:	 Subj:	Re: Background Process  O X-ListName: "VMS Internals, MACRO, & BLISS Discussions" <MACRO32@WKUVX1.BITNET>  Warnings-To: <> ! Errors-To: MacroMan@WKUVX1.BITNET 4 Sender: MacroMan%WKUVX1.BITNET@ULKYVM.LOUISVILLE.EDU X-Newsgroups: vmsnet.internals Subject: Re: Background Process 1 Message-ID: <1993May15.003711.2292@zl2tnm.gen.nz> - From: don%zl2tnm.gen.nz@ULKYVM.LOUISVILLE.EDU 5 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   J In article <1993May12.185805.1@ducvax.auburn.edu>, johnd@ducvax.auburn.edu  writes:F > 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 theC > background.  The clincher is that this C program has to initially E > as for input, then become a background process.  Is there a library B > call that tells the system to take the current process and placeG > it in the background?  I'm trying to avoid a fork() call at all cost.   3 There is a hack that does work.  It goes like this:   I Run your command as a DCL subprocess.  The subprocess, when it decides to I "background" itself, can then "detach" from DCL's "job control" facility.   H How?  You spoof DCL so that the parent process thinks the subprocess hasH executed an "ATTACH" command to pass control back to the parent, and the+ subprocess doesn't and just keeps on going.   E The following DCL code demonstrates this.  Run with "$ SPAWN @DETACH" G (assuming you called the command file DETACH.COM).  It's fairly easy to D implement in a HLL (like Macro 8-) if you need a callable procedure.  : $ read SYS$COMMAND/prompt="Please enter something: " xyzzyH $ 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.M $       ! 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 	 $       ! 7 $       ! We're detached now.  Wait a bit and prove it. 	 $       !  $ wait 0:0:5A $ write SYS$OUTPUT "You entered: ", xyzzy, ".  I'll go away now."  $ exit  E I should of course point out that all this is highly undocumented and G unsupported. It can also make things break if you don't hold your mouth I right.  (Try SPAWNing immediately after the procedure returns control, ie 6 before it prints the "You entered..." line and exits.)    I Don Stokes, ZL2TNM (DS555)                       don@zl2tnm.gen.nz (home) I Network Manager, Computing Services Centre           don@vuw.ac.nz (work) I Victoria University of Wellington, New Zealand             +64-4-495-5052 