Kill after sleep

I could not make my sleep () program after using kill (pid, SIGTERM), what can I do?

The code I'm using is:

kill(PID_of_Process_to_be_killed,SIGTERM); sleep(5); --> this is not working sleep(5); --> this is working 

solution at the moment:

 kill(PID_of_Process_to_be_killed,SIGTERM); sleep(sleep(5)); 

but why the first dream after returning kill 0?

+4
source share
2 answers

Your sleep() call may end earlier due to signal reception. Check the return value. If this is 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 expired, the return value will be zero. If the sleep () function returns due to signal delivery, the return value will be a non-fixed amount (the requested time minus the time actually slept) in seconds

+6
source

Well, if you can't handle the signal, SIGTERM is death.

If its another process or thread sending a sleep signal returns an EINTR.

If you use the standard library instead of a direct system call (you probably), -1 is returned and errno = EINTR.

+3
source

All Articles