Fix restart command

* Correct shell scaping.
* Correctly rebuilding command line.
Fix first thread test to make it deterministic