🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.sgi.graphics
1 messages
1 total messages Started by LANGER STEVEN C Tue, 12 Jan 1993 02:54
unix pipes and X
#102
Author: LANGER STEVEN C
Date: Tue, 12 Jan 1993 02:54
101 lines
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.
---------------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads