Reduce the risk of losing track of state info

Changed the way broctl updates PIDs and crash flags by writing the new
values to disk immediately, one at a time, as soon as each new value is
available.  This reduces the chance of losing track of that info if
broctl is killed or terminated before a command finishes.

Also changed the way that the state file is updated when each command
finishes by doing the update as an atomic operation, so that even in the
worst case (broctl is killed or terminated while updating that file) we
never lose existing entries.