kill after sleep
i couldnt make my program sleep() after using kill(pid,SIGTERM) what can i do ?
The code i'm using:
kill(PID_of_Process_to_be_killed,SIGTERM);
sleep(5); --> t开发者_开发技巧his is not working
sleep(5); --> this is working
the solution for now is:
kill(PID_of_Process_to_be_killed,SIGTERM);
sleep(sleep(5));
but why the first sleep after kill return 0 ?
Your sleep()
call may be terminating early due to receiving a signal. Check the return value. If it's positive, you might want to sleep()
again on that value. From http://www.manpagez.com/man/3/Sleep/:
If the sleep() function returns because the requested time has elapsed, the value returned will be zero. If the sleep() function returns due to the delivery of a signal, the value returned will be the unslept amount (the requested time minus the time actually slept) in seconds
Well unless you handle the signal, SIGTERM is death.
If its another process or thread sending the signal sleep returns EINTR.
If you're using the standard library instead of direct system call (you probably are) sleep returns -1 and errno = EINTR.
精彩评论