#: 7782 S12/OS9/68000 (OSK)
26-Oct-90 17:09:32
Sb: #7780-Help with C
Fm: Kevin Darling (UG Pres) 76703,4227
To: MAS 76336,3226 (X)
Hi Robert - I'm no UNIX guru, and others here may come up with a totally
different way of handling a login shell startup for you... but I think I can
help some on at least how pipes/forks are handled:
Under OS9, child processes inherit at least the parent's standard three paths
(in, out, err) at Fork time. I believe under OS9/68K (OSK) you can change that
number, but we'll ignore that for now.
Therefore the trick is to have the parent process redirect any of those paths
_before_ forking a child. One sequence might be:
open pipe:(p0) /* parent opens two pipe paths
open pipe:(p1)
dup (0):(save0) /* parent saves copy of stdin/out for later
dup (1):(save1)
close (0), dup(p0) /* redirect parent's stdin/out to pipes
close (1), dup(p1)
fork child /* child starts up; inherits pipes as stdin/out
close (0), dup(save0) /* parent resets its original stdin/out
close (save0) and closes copies
close (1), dup(save1)
close (save1)
...
write (p0) /* parent uses pipe paths to comm with child
read (p1)
In this way, children don't have to know about redirection (altho they could
use gs_opts to check path device types, if wished). best - kev
|