in reply to Detect Process End

one thing no one else noted ... and i hope it's just because you posted pseudocode ...

$a is a reserved variable for  sort. that could be anoother possible explanation.