一个wget实现的多进程简单投票器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<stdio.h>
#include<signal.h>
using std::cin;
using std::cout;
using std::endl;
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
void sig(int);
int main(){
signal(SIGCHLD,sig);
cout<<"start :"<<getpid()<<endl;
//sleep(10);
cout<<"请选择投个几号(1-16):";
int ch=1;
cin>>ch;
int count=0;
cout<<"请输入要投的票数:";
cin>>count;
ch=87+ch;
char cmd[100];
sprintf(cmd,"wget --post-data="voteId[]=%d&Submit=" http://www.qdnmg.com/vote/vote.php?action=vote&cid=13",ch);
printf("%sn",cmd);
for(int i=0;i<count;i++){
if(fork()==0){
system(cmd);
return 0;
break;
}
}
sleep(10);
cout<<"投票成功"<<endl;
//cout<<"child:"<<ch_pid<<"was killed"<<endl;
return 0;
}
void sig(int signal){
int ch_pid;
int sta;
while(ch_pid=(waitpid(-1,&sta,0)>0)){
cout<<"child "<<ch_pid<<" was killed"<<endl;
sleep(3);
system("rm vote.php*");
}
return;
}