home *** CD-ROM | disk | FTP | other *** search
- From: pirson@misty.boeing.com (Chris Pirson)
- Date: Tue, 5 Jan 1993 00:54:10 GMT
- Subject: Re: HELP pipe communication?
- Message-ID: <66040009@misty.boeing.com>
- Organization: Boeing Commercial Airplane BCS Support
- Path: sparky!uunet!bcstec!misty!pirson
- Newsgroups: comp.windows.x.motif
- References: <1993Jan3.192240.1168@vela.acs.oakland.edu>
- Lines: 80
-
- sglanger@vela.acs.oakland.edu (LANGER STEVEN C) writes:
-
- >I've got a foreground X app that launches a child process (non-
- >graphical) for data acquisition. I want to establish 2-way pipe
- >communication between said parent-child.
-
- >Vol 4 of the Xt Intrinsics Manual by Adrian Nye shows on pg.282-283
- >how to use popen, but this only gives one way communication and
- >since the example didn't show how to modify the child, I could
- >not even get the example to work.
-
- >Volume 6, Motif Programming Manual by Dan Heller on pg. 699 says,
-
- >1. call pipe to get the input and output channels
- >2. call fork to spawn the child
- >3. use dup2 on the child side to redirect stdout and stdin.
- >4. use XtAppAddInput to monitor the pipes.
-
- > Sadly, there is no code example of this procedure.
-
- >I've since gone to the man pages and I see that pipe(int *fildes)
- >returns two ints;
- > filedes[0] being for read and
- > filedes[1] being for write
-
- >XtAppAddInput requirs bona fide FILE pointers. How do I get them from
- >pipes it returns? Also, my man server knows a total of 2
- >sentences about buf2. I really could use a code fragment from both sides
- >to put this puzzle together. Any UNIX interprocess communication
- >GURUS with X experience out there? I'll post a summary of methods
- >if there is interest.
-
- >--thanks in advance, steve
-
-
- >P.S. I'm running an SGI Indigo with Os 4.0.1
-
- I have done this sucessfully by taking the sample source code in the
- pipe man page and used XtAppAddInput to get the input back to my
- application. XtAppAddInput (O'Reilly Volume 5, pg 86) uses a file
- descriptor returned from the pipe as-is, not a FILE *.
-
- I have this running on an HP750 running HP-UX 8.07, X11R4.
-
- --------snip------------snip------------snip------------snip--------
- static int start_cpu_monitor(void)
- {
- int pipefd[2];
-
- if(pipe(pipefd) == -1) return OUT_OF_CHANNELS;
-
- if((cpu_monitor_pid = fork()) == (pid_t)0) {
- /* child process comes here */
- close(1); /* replace stdout with the pipe */
- dup(pipefd[1]);
- close(pipefd[0]);
- execlp(CPU_MONITOR, CPU_MONITOR, CPU_UPDATE_INTERVAL, (char *)0);
- fprintf(stderr, "WARNING: CPU Monitor failed to start\n");
-
- }else if(cpu_monitor_pid > (pid_t)0) {
- /* parent process comes here */
-
- /* give input pipe to X server */
-
- XtAppAddInput(UxAppContext, pipefd[0],
- (XtPointer)XtInputReadMask, handle_cpu_monitor_input, NULL);
- }
- return EXEC_GOOD;
- }
- --------snip------------snip------------snip------------snip--------
- CPU_MONITOR is a function like vmstat, sending status to stdout (now the
- pipe) periodically.
- handle_cpu_monitor_input is an XtInputCallbackProc which is called any
- time something comes in over the pipe from CPU_MONITOR.
-
- --
- Chris Pirson |B\______o=o=o. Flight Test Engineering
- --=o=o=o=o=o=o=> Boeing Commercial Airplanes
- pirson@misty.boeing.com / ,' Boeing Field, Seattle, WA
- uunet!bcstec!misty!pirson .. /,' 76 MIPS at 40,000 feet!
-