wait_for_single_pid (pid, flags)
     pid_t pid;
     int flags;
{
  register PROCESS *child;
  sigset_t set, oset;
  int r, job;

  BLOCK_CHILD (set, oset);
  child = find_pipeline (pid, 0, (int *)NULL);
  UNBLOCK_CHILD (oset);

  if (child == 0)
    {
      r = bgp_search (pid);
      if (r >= 0)
	return r;
    }

  if (child == 0)
    {
      if (flags & 1)
	internal_error (_("wait: pid %ld is not a child of this shell"), (long)pid);
      return (127);
    }

  r = wait_for (pid);

  /* POSIX.2: if we just waited for a job, we can remove it from the jobs
     table. */
  BLOCK_CHILD (set, oset);
  job = find_job (pid, 0, NULL);
  if (job != NO_JOB && jobs[job] && DEADJOB (job))
    jobs[job]->flags |= J_NOTIFIED;
  UNBLOCK_CHILD (oset);

  /* If running in posix mode, remove the job from the jobs table immediately */
  if (posixly_correct)
    {
      cleanup_dead_jobs ();
      bgp_delete (pid);
    }

  return r;
}
wait_for_single_pid (pid, flags)
     pid_t pid;
     int flags;
{
  register PROCESS *child;
  sigset_t set, oset;
  int r, job;

  BLOCK_CHILD (set, oset);
  child = find_pipeline (pid, 0, (int *)NULL);
  UNBLOCK_CHILD (oset);

  if (child == 0)
    {
      r = bgp_search (pid);
      if (r >= 0)
	return r;
    }

  if (child == 0)
    {
      if (flags & 1)
	internal_error (_("wait: pid %ld is not a child of this shell"), (long)pid);
      return (127);
    }

  r = wait_for (pid);

   
  BLOCK_CHILD (set, oset);
  job = find_job (pid, 0, NULL);
  if (job != NO_JOB && jobs[job] && DEADJOB (job))
    jobs[job]->flags |= J_NOTIFIED;
  UNBLOCK_CHILD (oset);

   
  if (posixly_correct)
    {
      cleanup_dead_jobs ();
      bgp_delete (pid);
    }

  return r;
}