Article View: comp.sys.sgi.graphics
Article #102unix pipes and X
From: LANGER STEVEN C
Date: Tue, 12 Jan 1993 02:54
Date: Tue, 12 Jan 1993 02:54
101 lines
2943 bytes
2943 bytes
Despite the help of several netters, I cannot seem to master the
mechanics of inter-process communication via pipes. Ultimately,
I want 2-way communication between a parent and child process.
This is what I've tried so far;
/*
* parent.c launches child and should get child's output
* standard include files
*/
int pipes[2];
void cbfunc (Widget w, XtPointer data, XtPointer dummy);
main (int argc, char **argv)
{
XtAppContext app_parent;
Widget topLevel;
topLevel = XtVaAppInitialize (&app_parent, "Parent", NULL, 0,
&argc, argv, NULL, NULL);
pipe (pipes);
if (fork() != 0)
{
XtAppAddInput (app_parent, pipes[0], XtInputReadMask,
cbfunc, NULL);
}
else
{
status = dup2 (pipes[1], STDOUT_FILENO);
close (pipes[0]);
if (status < 0)
{
fprintf (stderr, "pipe error\n");
exit (0);
}
execlp ("child", "child", (char *)0);
}
XtRealizeWidget (topLevel);
XtAppMainLoop (app_parent);
}
void cbfunc (Widget w, XtPointer data, XtPointer dummy)
{
char buf[BUFSIZE] = "\0";
read (pipes[0], buf, sizeof(buf));
fprintf (stderr, "in Parent buf=%s\n", buf);
}
/*
*
* child.c prints to stdout & stderr every 10 seconds
* necessary includes
*/
void alarmcb (void);
main (void)
{
XtAppContext app_child;
app_child = XtCreateApplicationContext ();
signal (SIGALM, alarmcb);
alarm (10);
XtAppMainLoop (app_child);
}
void alarmcb (void)
{
fprintf (stdout, "in child \n");
fprinf (stderr, "in child\n");
signal (SIGALM, alarmcb);
alarm (10);
}
Everything runs, the child prints to the screen via the stderr and I get
no error codes, but the parent callback func is never entered. Could
anyone please tell me what the error is?
--thanks in advance, steve
--
Steve Langer sglanger@argo.acs.oakland.edu (VMS)
Oakland University sglanger@vela.acs.oakland.edu (Ultrix)
---------------------------------------------------------------------------
Standard disclaimers apply. In addition, the author makes no guarantees,
concerning the grammatical accuracy of his writing. Therefore, any ^B's, ^C's,
midword character additions/deletions and other non-sense which occurs (after
the work leaves the author's decade old text editor via his decade old Amiga,
struggles through a local 1200 baud Merit server to be further mauled via the
remote VAX mail servers) is someone elses problem - namely yours.
---------------------------------------------------------------------------
Technical Details
Message-ID:
<1993Jan12.025440.1874@vela.acs.oakland.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!vela!sglangerShow Full Headers
Complete Article Headers
Newsgroups: comp.sys.sgi.graphics Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!vela!sglanger From: sglanger@vela.acs.oakland.edu (LANGER STEVEN C) Subject: unix pipes and X Message-ID: <1993Jan12.025440.1874@vela.acs.oakland.edu> Organization: Oakland University, Rochester MI. Distribution: na Date: Tue, 12 Jan 1993 02:54:40 GMT Lines: 101