监控线程是否存在

mac2025-06-01  32

struct pthread_info{     pthread_t thread_id;     char thread_name[64]; }thread_id;

struct pthread_info all_pthread_info[20]; int cur_pthread_num = 0;

        if(thread_timer_cnt++ > 50)         {             for(int i = 0; i < cur_pthread_num; i++)             {                 int pthread_kill_err;                 pthread_kill_err = pthread_kill(all_pthread_info[i].thread_id,0);//发送信号0,这是一个保留信号,用来检测线程是否有回应                 if(pthread_kill_err == ESRCH)                 {                     WRT_LOG(ERROR_INFO,"%s is dead,proces exit\n",all_pthread_info[i].thread_name);                     //exit(0);                 }                 else if(pthread_kill_err == 0)                 {                     WRT_LOG(ERROR_INFO,"%s is alive\n",all_pthread_info[i].thread_name);                 }                 thread_timer_cnt = 0;             }         }

最新回复(0)