#include
#include
#include
#include
//#include
#define MAX_CHILD_NUMBER 10;
int proc_number=0;
void do_sth();
int main(int argc, char* argv[]){
int child_proc_number=MAX_CHILD_NUMBER;
int i, id;
pid_t child_pid;
pid_t pid[10]={0};
//if(argc>1){
//child_proc_number=atoi(argv[1]);
//child_proc_number=(child_proc_number>10)?10:child_proc_number;
//}
//创建进程
for (i=0; i
if( (child_pid=fork())==0 ){
proc_number=i;
do_sth();
}else{
pid[i]=child_pid;
}
}
//KILL PROC
if(child_pid!=0){
printf("the pid you want to kill(q to quit): ");
while(scanf("%d",&id)){
if (id==113)
break;
else
kill(id,SIGKILL);
}
}
//KILL ALL
kill(0,SIGKILL);
return 0;
}
void do_sth(){
for(;;){
printf("this it process No.%d and its pid is %d.\n",proc_number,getpid());
sleep(2);//主动阻塞两秒钟
}
}
取消
评论