POSIX compatible exit handling

Implement suggestion from Github Issue #44 

@Luzifer or @mlafeldt Please take a look.