1) 读取进程pid号
2) 调用kill系统调用,给进程发SIGTERM 信号。
代码:
- static int kill_thread(void)
- {
- FILE *f;
- int pid = 0; /* pid number from pid file */
- if((f = fopen(“test.pid”, "r")) == 0)
- {
- fprintf(stderr, "Can't open pid file");
- return -1;
- }
- if(fscanf(f, "%d", &pid)!= 1)
- {
- }
- /* send signal SIGTERM to kill */
- if(pid > 0)
- {
- kill(pid, SIGTERM);
- }
- fclose(f);
- return 0;
- }
阅读(213) | 评论(0) | 转发(0) |