/*
slave.c - returns process id and hostname to master
Jeffrey Grafton <jgrafton@tjhsst.edu> - 11/12/2002 15:57

This program is released under the GNU General Public License.
A copy of this license is available online at
http://www.gnu.org/copyleft/gpl.html.
*/

#include <stdio.h>
#include <pvm3.h>

/* The two below must match those in master.c */
#define RECV_MSGTYPE 1337 /* arbitrary number to specify message type when communicating */
#define SEND_MSGTYPE 4321 /* again, arbitrary */
#define HOSTNAME_MAXLEN 50

int
main (void)
{
    int my_tid, id, master;
    FILE *hostname_file;
    char hostname[HOSTNAME_MAXLEN];
    
/* Enrolls process into PVM */
    my_tid = pvm_mytid();

/* Receive data from master */
    pvm_recv(-1, RECV_MSGTYPE); /* Wait for correct message type */
    pvm_upkint(&id ,1, 1); /* receive id from master */ 

/* Get hostname of current computer */
    hostname_file = fopen("/etc/hostname", "r");
    fscanf(hostname_file, "%50s", hostname);
    fclose(hostname_file);
    
/* Send data back to master */
   pvm_initsend(PvmDataDefault);    /* Get Buffer ready to send data */
   pvm_pkint(&id, 1, 1);    /* Pack which id I am */
   pvm_pkint(&my_tid, 1, 1);   /* Pack my process id */
   pvm_pkstr(hostname);     /* Pack Reciprocal of number */
   master = pvm_parent();   /* Find out where I came from */
   pvm_send(master, SEND_MSGTYPE);  /* Send message back to parent process */

   return pvm_exit();
}  




