Try putting

proc_kill(4);

at the start of the function which is the problem.