監控線程是否存在

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章