Better poll and kill scripting for background and at.

Tested with local and remote background and at tasks.