コード例 #1
0
ファイル: 10-1.c プロジェクト: 1587/ltp
int main(void)
{
	pid_t pid;
	struct sigaction act;
	struct timeval tv;

	act.sa_sigaction = handler;
	act.sa_flags = SA_SIGINFO;
	sigemptyset(&act.sa_mask);
	sigaction(SIGCHLD, &act, 0);

	if ((pid = fork()) == 0) {
		/* child */
		while (1) {
			/* wait forever, or until we are
			   interrupted by a signal */
			tv.tv_sec = 0;
			tv.tv_usec = 0;
			select(0, NULL, NULL, NULL, &tv);
		}
		return 0;
	} else {
		/* parent */
		int s;
		int i;

		for (i = 0; i < NUMSTOPS; i++) {
			printf("--> Sending SIGSTOP\n");
			notification = 0;
			kill(pid, SIGSTOP);

			/*
			   Don't let the kernel optimize away queued
			   SIGSTOP/SIGCONT signals.
			 */

			wait_for_notification(CLD_STOPPED);

			printf("--> Sending SIGCONT\n");
			notification = 0;
			kill(pid, SIGCONT);
			/*
			   SIGCHLD doesn't queue, make sure CLD_CONTINUED
			   doesn't mask the next CLD_STOPPED
			 */
			wait_for_notification(CLD_CONTINUED);
		}

		kill(pid, SIGKILL);
		waitpid(pid, &s, 0);
	}

	if (child_stopped == NUMSTOPS && child_continued == NUMSTOPS) {
		printf("Test PASSED\n");
		return 0;
	}

	printf("Test FAILED\n");
	return -1;
}
コード例 #2
0
void
cmpi_client_code()
{
  wait_for_notification();
  notify_next();

  NOTE("PROCEEDING...");

  cmpi_driver* driver = driver_create();

  while (! driver->quitting)
  {
    driver_setup_fifo(driver);
    driver_process(driver);
  }

  NOTE("QUITTING");
}