Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!uwvax!mcvoy From: mcvoy@rsch.WISC.EDU (Lawrence W. McVoy) Newsgroups: comp.unix.questions Subject: argv ==> stdin, got it Message-ID: <2976@rsch.WISC.EDU> Date: Thu, 20-Nov-86 18:11:44 EST Article-I.D.: rsch.2976 Posted: Thu Nov 20 18:11:44 1986 Date-Received: Thu, 20-Nov-86 23:36:10 EST Organization: U of Wisconsin CS Dept Lines: 49 Keywords: pipe, fork, dup This works very well. My previous fears about speed were unfounded. Now, here's a question: what happen if I used vfork() instead? I thought that the parent sleeps until the child dies, but what if the child blocks? Like on I/O? Would that work even better? # include # define child_stdin output[1] yyerror(s) char* s; { fprintf(stderr, "%s\n"); } /* * code to fork a child and have control of the child's stdin/out * from usenet. Works. Fast, too. The idea is that the command line * is fed to the stdin of the child. This is so that you don't have * to f*ck with the stupid code in y.tab.c or lex.yy.c. It should work * for anything that wants stdin. */ main(argc, argv) char** argv; { int output[2]; int i; pipe(output); /* parent writes 1, child reads 0 */ if (fork() == 0) { /* child */ close(0); dup(output[0]); return yyparse(); } else { /* parent */ close(output[0]); /* write only */ for (i=1; i