process: Emit 'beforeExit' to allow more work

If the event listener schedules more work, the loop will be restarted,
otherwise, exit proceeds as usual.  Test immediates, timers, and
listening sockets will keep node alive, nextTick should not keep
node alive, after upcoming changes in tick handling.