The only function to kill processes that comes to my mind is proc_kill, and it can't be used for that purpose.
It is however possible to do something like this:
var functionIsRunning = 0; // A global variable
function theFunction()
{
// Set the variable to non-zero
functionIsRunning = 1;
// Run the function as long as functionIsRunning is non-zero
while(functionIsRunning != 0)
{
... // Code
}
}
This way you can stop the function by setting 'functionIsRunning' to 0.
Edit: Never use 'goto', please
