Fix multithreading, fetch remote PID

* select() now out of a mutex
* 'echo $$; ' prepended to the commandline reports PID