Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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); --> this 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 ?

like image 212
Ran S Avatar asked Jan 21 '23 23:01

Ran S


1 Answers

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

like image 50
Fred Larson Avatar answered Jan 28 '23 13:01

Fred Larson