当前位置: 论文资料 >> 计算机论文 >> 计算机网络 >> Windows
Windows



#include #include #include #include

void main(int argc,char *argv[]) { char cmd[128];

if (argc!=1) strcpy(cmd,argv[1]);

else  strcpy(cmd,”slave.exe”);

int pid=GetCurrentProcessId();

sprintf(cmd+strlen(cmd),” %d”,pid);

cout<<”Master: Starting:”<
cout.flush();

STARTUPINFO info;

memset(&info,0,sizeof(info));

info.cb=sizeof(info);

PROCESS_INFORMATION pinfo;

If(!CreateProcess(NULL,cmd,NULL,NULL,FALSE
c out<<” Master:Try naming slave process on the command line\n”; }

cout<<”Master:Sleeping\n”;

cout.flush();

Sleep(15000);

Cout<<”Master:Exiting\n”;

exit(0);}

程序清单 SLAVE程序 #include #include #include

void main(int argc,char *argv[])

{if (argc!=2) { cout<<”Slave:Please rrun MASTER.EXE instead.\n”;

exit(1);}

int pid=atoi(argv[1]);

HANDLE process=OpenProcess(PROCESS_QUERY_INFORMATION|SYNCHRONIZE,FALSE,pid);

if (!process) cot<<”Slave:Error opening process\n”;

cout<<”Slave :Waiting for master to finish\n”;

cout.flush();

if (WaitForSingleObject(process,INFINITE)==STAUTE_WAIT_0)

cout<<”Slave:Master completed\n”;

else cout<<”Slave:Unexpected error\n”;

exit(0);}

上一页  [1] [2]