Rewrote to avoid using perl Switch module, which may not be universally available.
Again do not use kill here, because pids may have expired and
something else may get killed.