Return process exit code for attach

Closes #2240