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;
- }