예제 #1
0
int main(int argc, const char *argv[])
{
	if (nice(2*MAX_PRIO) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (nice(-2*MAX_PRIO) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (setpriority(-1,0) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (getpriority(-1) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (setpriority(getpid(),2*MAX_PRIO) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (setpriority(getpid(),-1) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	
	if (setaffinity(-1, 0) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (setaffinity(getpid(), -1) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (setaffinity(getpid(), 3) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");
	if (getaffinity(-1) != -1)
		handle_error("Error: error checking for syscalls should be implemented.\n");

	printf(stdout, "hw4-test-err succeeded\n");

	exit();
}
예제 #2
0
static int
find_set_size (void)
{
  /* There is considerable controversy about how to determine the size
     of the kernel CPU mask.  The probing loop below is only intended
     for testing purposes.  */
  for (int num_cpus = 64; num_cpus <= INT_MAX / 2; ++num_cpus)
    {
      cpu_set_t *set = CPU_ALLOC (num_cpus);
      size_t size = CPU_ALLOC_SIZE (num_cpus);

      if (set == NULL)
	{
	  printf ("error: CPU_ALLOC (%d) failed\n", num_cpus);
	  return -1;
	}
      if (getaffinity (size, set) == 0)
	{
	  CPU_FREE (set);
	  return num_cpus;
	}
      if (errno != EINVAL)
	{
	  printf ("error: getaffinity for %d CPUs: %m\n", num_cpus);
	  CPU_FREE (set);
	  return -1;
	}
      CPU_FREE (set);
    }
  puts ("error: Cannot find maximum CPU number");
  return -1;
}