#ifdef SGI_CFG

/* Program to test shared process behavious on SGI systems */

#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/prctl.h>
#include <signal.h>
#include <sys/wait.h>

spid;
int boo;
int fds[2];

onSigchld()
{
	printf ("Child died\n");
	exit (-1);
}

smain()
{
	struct timeval tout;
	fd_set rfds;
	char c;

	printf ("shared process alive here\n");
	boo = 1;
	PRDA->usr_prda.fill[0] = 111;

	tout.tv_sec = 1;
	tout.tv_usec = 0;
	while (1)
	 { int n;

	   FD_ZERO(&rfds);
	   FD_SET(fds[0], &rfds);
	   n = select (FD_SETSIZE, &rfds, 0, 0, &tout);
	   if (n == 0)
	    { /* timeout */
	      printf ("tick\n");
	    }
	   else if (FD_ISSET(fds[0],&rfds))
	    { char com;
	      if (read (fds[0], &com, 1) <= 0)
	       { printf ("parent exited ... bye\n");
		 exit (0);
	       }
	      else
	       { printf ("com %d\n", com);
	       }
	    }
	   else
	    { printf ("bogus\n");
	    }
	 }
}

main()
{
	if (pipe(fds) < 0)
	 { perror ("pipe");
	   exit (-1);
	 }
	signal (SIGCHLD, onSigchld);
	prctl (PR_SETEXITSIG);
	if ((spid = sproc(smain, PR_SADDR, 0)) < 0)
	 { perror ("Couldn't create shared process");
	   exit (-1);
	 }
	if (spid)
	 { char com = 0;
	   printf ("parent\n");
	   while (1)
	    { sleep(3);
	      if (com++ == 4)
	       { exit (1);
	       }
	      write (fds[1], &com, 1);
	    }
	 }
	else
	 { printf ("child\n");
	   sleep(1);
	 }
}

#endif


