start the long remote service "sleep 40" stdout & stderr redirection is needed to avoid the local ssh hanging.
farpid=$(ssh me@farsys 'nohup sleep 40 1>/dev/null 2>&1 & echo $!')
We can kill the far process with ....
ssh me@farsys "kill -9 $farpid"