Use one master process to spawn task proccesses

Rather querying the database from many task processes, query it from a
master process and spawn worker processes only when there are tasks to
be processed.