Code:
static sem_t s_threadsem;
int main(void)
{
//initialize resources
#define NONE_PROCESS_SHARE 0
const unsigned int THREADCNT = 2;
if( 0 != sem_init(&s_threadsem, NONE_PROCESS_SHARE, THREADCNT) )
{
cout<<"sem_init fail" <<endl;
exit(-1);
}
while(1)
{
dowork();
sleep(2);
}
//destroy resources
sem_destroy(&s_threadsem);
return 0;
}
The code above do a infinite loop (like a server), If I use kill -9 or killall -9 to kill this process, Will the linux operating system reclaim the sem_t resource correctly? And what else kind resources would linux operating system not reclaim correctly(that we should take care)?
I wonder what mechanism do you guru use to stop and restart your process while not using kill -9?
Thanks in advance!