From help-octave-request at bevo dot che dot wisc dot edu Thu Feb 3 18:10:42 2000 Subject: waitpid usage From: "John S. Gwynne" To: help-octave at bevo dot che dot wisc dot edu Date: Thu, 03 Feb 2000 19:10:37 -0500 I'm trying to open a two-way pipe (with popen2) to create a dialog with another application. The problem I'm having is trying to release "waitpid" in between exchanged lines. In the example below, I send a text string to a program that echos it back. After sending the string, waitpid is called to wait on the child to echo. I can unblock waitpid by first closing the "in" pipe (closing the app) and the example finishes, but I need more than one exchange of dialog. I need to unblock waitpid without closing the application or pipe. How can I do that? "man waitpid" says... option 0: wait until signal is received or a child process exits (this is the default if the OPTIONS argument is missing) So... what signal can I send that will unblock, leave the pipe open, and how should it be coded? I tried a killpg with a SIGCONT without success and figured I need help at this point. HELP!! :) TIA, john gwynne ======================================================== ================= begin example ptest1.m =============== ======================================================== function ptest1() [in out pid] = popen2("myEcho"); if (pid == -1) error("Pipe failed\n"); end; fputs(in,"Test 1\n"); % works fine with an "fclose(in)" here, but that closes the pipe waitpid(pid); % would like to wait here until text is available % or some non-exit signal is received. fputs(stdout,fgets(out)); fflush(stdout); % would like to put more fputs/fgets here for dialog with application fclose(in); fclose(out); end; ======================================================== =================== end example ptest1.m =============== ======================================================== %%%%%%%%%%%%%%%%%%%%%%%%%% =============================================== ================ begin myEcho,c =============== =============================================== #include #include int main() { int ch; FILE *fid; fid = fopen("/tmp/hold","w"); if (!fid) perror("fopen failed"); while (EOF != (ch=getchar())) { fputc(ch,fid); fflush(fid); putchar((char)ch); if (ch == '\n') { fputc('.',fid); fflush(fid); if (killpg(0,18)) /* does this make sense? */ perror("Signal failed"); } } } =============================================== ================== end myEcho,c =============== =============================================== ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------