TS: busy refactoring and testing processtools's registerShutdownHandler and friends.