use PBS_NUM_CPU
a few more fixes in waiting and joining.

Most importantly work around linux kernel deadlock at processes
terminationg when NCPU > 58.