-   Programming (
-   -   what does kill -9 and killall -9 do and don't? (

fantasy1215 02-25-2013 09:31 PM

what does kill -9 and killall -9 do and don't?

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;
        //destroy resources
        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!

pan64 02-26-2013 04:23 AM

kill -9 will not allow to cleanup, so you should not use it. You should implement your own signal handler (sigint, siguser1, whatever) to stop your server and properly clean up.

NevemTeve 02-26-2013 05:57 AM

I don't know what happens with posix semaphores when the process ends; SystemV semaphores on the other hand can be used with option SEM_UNDO, meaning: undo the changes when the process terminates (see man 2 semop)

All times are GMT -5. The time now is 05:53 PM.