进程问题
zhuxz 2003-05-06 05:24:46 #include <unistd.h>
#include <stdio.h>
#include <rpc/rpc.h>
#include "Ex.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define HOST "localhost"
///////////////////////////////////////////////////////////////////////////////
CLIENT * handle;
myinfo getstr(int index);
////////////
void main()
{ myinfo RES;
handle= clnt_create(HOST,EXPROG,EXVERS,"tcp"); //与远程服务端链接
while( handle == 0 )
{
int pid = fork();
if(pid==0) {
if (execlp("./server","server",(char *) 0) <0) //启动远程的服务端
{
fprintf(stderr,"%s","error");
}
exit(0);
}
if (pid>0)
{
handle= clnt_create(HOST,EXPROG,EXVERS,"tcp");
}
}
//调用远段的程序
for(int i=0;i<17;i++){
RES = getstr(i);
fprintf(stderr, "<%d>%s\n", RES.index, RES.info);
}
}
//////////////////////////////////////////////////////////////////////////////////
为什么我执行后,老有多个server启动,而且父进程关闭了,server还流着