#: 11417 S12/OS9/68000 (OSK)
20-Jul-91 21:09:29
Sb: #11412-forks and pipes
Fm: Bob van der Poel 76510,2203
To: Kevin Darling 76703,4227 (X)
Kevin,
Here's a bit of code. Remember, this is 'C' -- but since it just calls the
system F$Fork even die-hard assembler types like you should be able to help
:
First off, a bit of the section which starts the pipeline:
char *argv[MAXARGS];
FILE *out_file;
int childnum, pipe, oldin, oldout, os9fork();
extern char **environ;
if((pipe=open("/pipe",S_IREAD+S_IWRITE))<0)
terminate("Unable to open '/pipe'");;
oldin=dup(0); /* save current stdin/out */
oldout=dup(1);
close(0); /* set stdin to new pipe file */
dup(pipe);
close(1); /* set stdout to current output file */
dup(fileno(out_file));
argv[0]="shell";
argv[1]=newprog;
argv[2]=0;
childnum=os9exec(os9fork,argv[0],argv,environ,0,0);
close(0); /* restore original stdin */
dup (oldin);
close(oldin);
close(1); /* restore original stdout */
dup (oldout);
close(oldout);
if(childnum<0){ /* fork failure, close the pipe file */
childnum=0;
close(pipe);
terminate("Unable to fork pipe process");
}
else{
fclose(out_file); /* close old output file */
out_file=fdopen(pipe,"w"); /* set to pipefile */
}
And here is the snippet which gives the problem.
fclose(out_file); /* close down the pipeline */
/* wait for a pipe process to finish it's thing... */
if(childnum){
wait(0);
childnum=0;
}
Continued next message.
|