read child output after local thun/3
This commit is contained in:
parent
2057d9ee74
commit
a5fb17cc48
|
|
@ -1,25 +1,29 @@
|
||||||
:- multifile(func/3).
|
:- multifile(func/3).
|
||||||
|
|
||||||
func(fork, [F, G|S], [X, Y|S]) :-
|
func(fork, [F, G|S], [X, Y|S]) :-
|
||||||
fork(F, S, X, ChildPID),
|
fork(F, S, R, ChildPID),
|
||||||
thun(G, S, [Y|_]),
|
thun(G, S, [Y|_]),
|
||||||
|
read_pipe(R, X),
|
||||||
wait(ChildPID, Status). % FIXME check status!!!
|
wait(ChildPID, Status). % FIXME check status!!!
|
||||||
|
|
||||||
fork(Expr, Stack, Result, ChildPID) :-
|
fork(Expr, Stack, In, ChildPID) :-
|
||||||
mkpipe(In, Out),
|
mkpipe(In, Out),
|
||||||
fork_prolog(ChildPID),
|
fork_prolog(ChildPID),
|
||||||
bar(ChildPID, In, Out, Expr, Stack, Result).
|
bar(ChildPID, In, Out, Expr, Stack).
|
||||||
|
|
||||||
bar(0, In, Out, Expr, Stack, Result) :-
|
bar(0, In, Out, Expr, Stack) :-
|
||||||
close(In),
|
close(In),
|
||||||
thun(Expr, Stack, [Result|_]),
|
thun(Expr, Stack, [Result|_]),
|
||||||
w(Out, Result),
|
w(Out, Result),
|
||||||
close(Out),
|
close(Out),
|
||||||
halt.
|
halt.
|
||||||
|
|
||||||
bar(P, In, Out, Expr, Stack, Result) :-
|
bar(PID, _, Out, _, _) :-
|
||||||
integer(P), P =\= 0,
|
integer(PID),
|
||||||
close(Out),
|
PID =\= 0,
|
||||||
|
close(Out).
|
||||||
|
|
||||||
|
read_pipe(In, Result) :-
|
||||||
select([In], R, [], _, 1500),
|
select([In], R, [], _, 1500),
|
||||||
(R=[In] ->
|
(R=[In] ->
|
||||||
read(In, Result)
|
read(In, Result)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue