/***************************************************/
/*  PVM Example Program                            */
/*  Simple Send and Receive        slave1.c        */
/*                                                 */
/***************************************************/

#include <stdio.h>
#include <time.h>
#include "/usr/pvm3/include/pvm3.h"

main()
 { int mytid, nproc;
   int master, msgtype;
   int test=0; 
   int n=0, ch;
   int num;
   char str[50];
   FILE *fp;

/*  This routine grabs the name of the host Linux Machine from a file */
   fp = fopen ("/etc/issue", "r");  // This file is used for logon prompts

   while((ch = fgetc(fp)) != EOF) {
      if (ch== '(') {   // Scan through file until finding the parentheses
         test = 1;
         }
      if (test)str[n++] = ch;  // Read the hostname into a string variable
     }
  
   str[n] = '\0';   // Terminate the string with a null character
   fclose (fp);

/* Enroll in pvm */
   mytid = pvm_mytid();    // Get my processor ID

/* Receive data from master */
   msgtype = 0;  		// This was arbitrarily set in master.c
   pvm_recv( -1, msgtype );	// Get ready to receive initial data
   pvm_upkint(&num,1, 1);     	// Unpack Randum Number 

/* Send data back to master */
   pvm_initsend( PvmDataDefault );  	// Get ready to send data
   pvm_pkint( &mytid, 1, 1 );     	// Pack which processor I am
   pvm_pkint( &num, 1, 1);
   
   pvm_pkstr( str );                   // Pack the string
   msgtype = 5;                        // Identify message type
   master = pvm_parent();              // Find out where I came from
   pvm_send( master, msgtype );        // Send message back to parent process

/* Program finished. Exit PVM before stopping */
   pvm_exit();

}  
  
