Exemplo n.º 1
0
void
badboy_fork ()
{
	int status, pid;

      status = fork ();
      badboy_pid = status;
      if (status == 0)	/* badboy */
	{
#ifdef DEBUG_LATE_BADBOY
	  sleep(ntries*MAX_TRY_TIME+10);
#else
	  badboy_loop ();
#endif
	  exit (0);	/* tough guy */
	}
      else if (status < 0)
	perror ("fork");
      else			/* parent watching over badboy */
	{
	  if (verbose_level > 3)
	  	printf ("badboy pid = %d\n", badboy_pid);

/* don't trust the child to return at night */
      my_signal (SIGALRM, monitor_fcn);
      alarm (ntries*MAX_TRY_TIME);

	  pid = waitpid (-1, &status, WUNTRACED);
	  if (pid <= 0)
	  {
		  perror ("wait");
	  } else {
	  	if (verbose_level > 3)
		  printf ("pid %d exited with status %d\n", pid, status);
		#if 0
		record_status(status);
		#endif
	   }
	}	/* parent */
	alarm(0);
}
Exemplo n.º 2
0
void badboy_fork()
{
	int status, pid;
	pid_t child;
	child = fork();
	badboy_pid = status;
	switch (child) {
	case -1:
		perror("fork");
	case 0:
#ifdef DEBUG_LATE_BADBOY
		sleep(ntries * MAX_TRY_TIME + 10);
#else
		badboy_loop();
#endif
		exit(0);
	default:
		if (verbose_level > 3)
			printf("badboy pid = %d\n", badboy_pid);

		/* don't trust the child to return at night */
		my_signal(SIGALRM, monitor_fcn);
		alarm(ntries * MAX_TRY_TIME);

		pid = waitpid(-1, &status, WUNTRACED);
		if (pid <= 0)
			perror("wait");
		else {
			if (verbose_level > 3)
				printf("pid %d exited with status %d\n",
				       pid, status);
#if 0
			record_status(status);
#endif
		}
	}
	alarm(0);
}