/*
Program hello.c
*/
#include <stdio.h>
#include "pvm3.h"
main()
{
int cc[10], tid[10],i;
char buf[10][100];
printf("i'm t%x\n", pvm_mytid());
for ( i=0; i<=9; i++ ){
cc[i] = pvm_spawn("hello_other", (char**)0, 0, "", 1, &tid[i]);
if (cc[i] == 1) {
cc[i] = pvm_recv(-1, -1);
pvm_bufinfo(cc[i], (int*)0, (int*)0, &tid[i]);
pvm_upkstr(buf[i]);
printf("from t%x: %s\n", tid[i], buf[i]);
} else
printf("can't start hello_other\n");
}
pvm_exit();
exit(0);
}
Das Slave-Programm hello_other.c wird vom obigen Masterprogramm gestartet. Seine erste Handlung ist das Abfragen der Tid des Masterprozesses, die es via pvm_parent() erfährt. Danach fragt es den Hostnamen des Clients ab, auf dem es läuft, und überträgt ihn nach dem initialisieren des ``Send Buffers'' mit pvm_initsend() per pvm_send() zum Master. pvm_pkstr() platzierte den String im Sendepuffer.
/*
Slave-Program hello_other.c
*/
#include "pvm3.h"
main()
{
int ptid;
char buf[100];
ptid = pvm_parent();
strcpy(buf, "hello, world from ");
gethostname(buf + strlen(buf), 64);
pvm_initsend(PvmDataDefault);
pvm_pkstr(buf);
pvm_send(ptid, 1);
pvm_exit();
exit(0);
}