请教:怎么反复执行某个进程,反复杀掉
要求执行某个进程或程序,然后杀死它,再执行,再杀死,小弟整了一天了,都快晕了。。。
到底应该怎么做?最好有个伪代码,小弟先谢了
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/wait.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <signal.h>
8 #include <time.h>
9
10 void handler()
11 {
12 exit(0);
13 }
14
22
23 int main()
24 {
25 pid_t pid;
26 int status;
27 srand(time(NULL));
28 int t;
29
30
31 if((pid=fork())<0)
32 printf("error in fork!");
33 else
34 if(pid==0){
35 (void) execle("./test",NULL , NULL, NULL); //这里不返回!!!!!!!!!
36 printf("I am the child process, my process ID is %d\n",getpid());
37 }
38 else{
39 t = rand()%10;
40 sleep(t);
41 kill(pid, SIGTERM);
42 wait(&status);
43 printf("killed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
44 printf("I am the parent process, my process ID is %d\n",getpid());
45 }
46 printf("i am the end\n");
47 exit(0);
48 return 0;
49 }