/* hey.c: administrator */
#include <stdio.h>
#include "pvm3.h"

#define NUMPROC 3   /* number of copies of hey_you to spawn */

main()
{
	int i, cc[NUMPROC], tid[NUMPROC];
	char buf[100];

	/* get parent id and print it */
	printf("i'm the parent t%x\n", pvm_mytid());

	/* spawn one task on available machines */
	for (i = 0; i < NUMPROC; i++) {
	     cc[i] = pvm_spawn("hey_you", (char**)0, 0, "", 1, &tid[i]);
	     printf("successfully spawned hey_you as t%x\n", tid[i]);
	}

	/* for each process spawned (indexed by i), if properly spawned 
	   (cc[i]=1), then receive data from child process and print it */
	for (i = 0; i < NUMPROC; i++) {
	if (cc[i] == 1) {
		cc[i] = pvm_recv(-1, -1);
		pvm_bufinfo(cc[i], (int*)0, (int*)0, &tid[i]);
		pvm_upkstr(buf);
		printf("from child t%x: %s\n", tid[i], buf);

	} else
		printf("can't start hello_other\n");

   }
	pvm_exit();

	exit(0);
}

