当前位置: 首页>>代码示例>>C++>>正文


C++ sched_getscheduler函数代码示例

本文整理汇总了C++中sched_getscheduler函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_getscheduler函数的具体用法?C++ sched_getscheduler怎么用?C++ sched_getscheduler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sched_getscheduler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{

	int result0 = -1;
	int result1 = -1;

	result0 = sched_getscheduler(0);
	result1 = sched_getscheduler(getpid());

	if (result0 == result1 &&
	   errno == 0) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (result0 != result1) {
		printf("Different results between pid == 0 "
		       "and pid == getpid().\n");
		return PTS_FAIL;
	} else {
		perror("Unexpected error");
		return PTS_FAIL;
	}

	printf("This code should not be executed.\n");
	return PTS_UNRESOLVED;
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:25,代码来源:1-1.c

示例2: testBadParams

void testBadParams()
{
        int id = fork();
        int status;
        if (id>0)
        {
                struct sched_param param;
                int expected_requested_time = 7;
                int expected_level = 51;
                param.lshort_params.requested_time = expected_requested_time;
                param.lshort_params.level = expected_level;
                assert(sched_setscheduler(id, SCHED_LSHORT, &param) == -1);
                assert(errno = 22);
                assert(sched_getscheduler(id) == 0);

                expected_requested_time = 310000;
                expected_level = 7;
                param.lshort_params.requested_time = expected_requested_time;
                param.lshort_params.level = expected_level;
                assert(sched_setscheduler(id, SCHED_LSHORT, &param) == -1);
                assert(errno = 22);
                assert(sched_getscheduler(id) == 0);
                wait(&status);
                printf("OK\n");
        } else if (id == 0) {
                doShortTask();
                _exit(0);
        }
}
开发者ID:lotemf,项目名称:OS-234123,代码行数:29,代码来源:uri1_Uri.c

示例3: main

int main(){
	int old_priority, old_policy, new_policy;
	struct sched_param param;
	int invalid_policy;

	invalid_policy = 0;
	/* Linux does not treat minus value as invalid for policy */
	while(invalid_policy == SCHED_OTHER || 
		invalid_policy == SCHED_FIFO ||
		invalid_policy == SCHED_RR ||
		invalid_policy == SCHED_BATCH)
	invalid_policy++;

	if(sched_getparam(getpid(), &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}	
	old_priority = param.sched_priority;

	old_policy = sched_getscheduler(getpid());
	if(old_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	sched_setscheduler(0, invalid_policy, &param);

	if(errno == 0) {
		printf("No error occurs, could %i be a valid value for the scheduling policy ???\n", invalid_policy);
		return PTS_UNRESOLVED;
	}

	if(sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	new_policy = sched_getscheduler(getpid());
	if(new_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}
		

	if(old_policy == new_policy && 
	   old_priority == param.sched_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}
	
	if(param.sched_priority != old_priority) {
		printf("The param has changed\n");
	}
	if(new_policy != old_policy) {
		printf("The policy has changed\n");
	}
	return PTS_FAIL;
}
开发者ID:CSU-GH,项目名称:okl4_3.0,代码行数:58,代码来源:17-5.c

示例4: main

int main(void)
{
    int old_priority, old_policy, new_policy;
    struct sched_param param;
    int invalid_policy;
    char *label;
    pid_t pid = getpid();
    int rc;

    invalid_policy = INT_MAX;

    label = "sched_getparam()";
    rc = sched_getparam(pid, &param);
    if (rc)
        goto unresolved;
    old_priority = param.sched_priority;

    label = "sched_getscheduler()";
    rc = sched_getscheduler(pid);
    if (rc < 0)
        goto unresolved;
    old_policy = rc;

    label = "sched_setscheduler() - invalid policy succeeded?";
    rc = sched_setscheduler(0, invalid_policy, &param);
    if (!rc)
        goto unresolved;

    label = "sched_getparam()";
    rc = sched_getparam(pid, &param);
    if (rc)
        goto unresolved;

    label = "sched_getscheduler()";
    rc = sched_getscheduler(pid);
    if (rc < 0)
        goto unresolved;
    new_policy = rc;

    if (old_policy != new_policy) {
        printf("Failed: invalid policy change, old: %u, new %u\n",
               old_policy, new_policy);
        exit(PTS_FAIL);
    }

    if (old_priority != param.sched_priority) {
        printf("Failed: invalid priority change, old: %u, new %u\n",
               old_priority, param.sched_priority);
        exit(PTS_FAIL);
    }

    printf("Test PASSED\n");
    return PTS_PASS;

unresolved:
    ERR_MSG(label, rc);
    return PTS_UNRESOLVED;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:58,代码来源:17-5.c

示例5: main

int main(){
	int policy, result;
	int old_priority, old_policy, new_policy;
	struct sched_param param;

	if(sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}	
	old_priority = param.sched_priority;

	old_policy = sched_getscheduler(getpid());
	if(old_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	/* set a sched_ss_repl_period lower than the sched_ss_init_budget */
	param.sched_ss_repl_period.tv_sec = 1;
	param.sched_ss_repl_period.tv_nsec = 0;

	param.sched_ss_init_budget.tv_sec = 2;
	param.sched_ss_init_budget.tv_nsec = 0;
	
	param.sched_priority = sched_get_priority_max(SCHED_SPORADIC);

	result = sched_setscheduler(0, SCHED_SPORADIC, &param);
      
	if(sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	new_policy = sched_getscheduler(getpid());
	if(new_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}
		

	if(old_policy == new_policy && 
	   old_priority == param.sched_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}
	
	if(param.sched_priority != old_priority) {
		printf("The param has changed\n");
	}
	if(new_policy != old_policy) {
		printf("The policy has changed\n");
	}
	return PTS_FAIL;
	

}
开发者ID:crystax,项目名称:android-vendor-openpts,代码行数:56,代码来源:17-3.c

示例6: main

int main(void)
{
	int invalid_priority;
	int old_priority, old_policy, new_policy;
	struct sched_param param;

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	old_policy = sched_getscheduler(getpid());
	if (old_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	invalid_priority = sched_get_priority_max(SCHED_SPORADIC);
	if (invalid_priority == -1) {
		perror("An error occurs when calling sched_get_priority_max()");
		return PTS_UNRESOLVED;
	}

	/* set an invalid priority */
	invalid_priority++;
	param.sched_ss_low_priority = invalid_priority;

	sched_setscheduler(0, SCHED_SPORADIC, &param);

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	new_policy = sched_getscheduler(getpid());
	if (new_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	if (old_policy == new_policy && old_priority == param.sched_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}

	if (param.sched_priority != old_priority) {
		printf("The param has changed\n");
	}
	if (new_policy != old_policy) {
		printf("The policy has changed\n");
	}
	return PTS_FAIL;

}
开发者ID:1587,项目名称:ltp,代码行数:55,代码来源:17-2.c

示例7: main

int main() {
	int max_priority, old_priority, old_policy, new_policy;
	struct sched_param param;

	if (sched_getparam(getpid(), &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	old_policy = sched_getscheduler(getpid());
	if (old_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	/* Make sure that param.sched_priority != old_priority */
	max_priority = sched_get_priority_max(SCHED_SPORADIC);
	param.sched_priority = (old_priority == max_priority) ?
		sched_get_priority_min(SCHED_SPORADIC) :
		max_priority;

	param.sched_ss_max_repl = 0;

	sched_setscheduler(0, SCHED_SPORADIC, &param);

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	new_policy = sched_getscheduler(getpid());
	if (new_policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	if (old_policy == new_policy &&
	   old_priority == param.sched_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	}

	if (param.sched_priority != old_priority) {
		printf("The param has changed\n");
		return PTS_FAIL;
	}
	if (new_policy != old_policy) {
		printf("The policy has changed\n");
		return PTS_FAIL;
	}

}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:53,代码来源:17-4.c

示例8: main

int main()
{
    sched_getscheduler(0);
    //staptest// sched_getscheduler (0) = 0

    sched_getscheduler((pid_t)-1);
    //staptest// sched_getscheduler (-1) = -NNNN (EINVAL)

    sched_getscheduler(999999);
    //staptest// sched_getscheduler (999999) = -NNNN (ESRCH)

    return 0;
}
开发者ID:Open-Party,项目名称:systemtap,代码行数:13,代码来源:sched_getscheduler.c

示例9: main

int main() {
	int rc;
	rc = sched_getscheduler(0);
	printf("Init sched: %d\n", rc);
	rc = sched_setscheduler(0, SCHED_POLICY_MYCFS, &MYPARAM);
	printf("Rc from set: %d\n", rc);
	if(rc == -1)
		printf("Errno %d: %s\n", errno, strerror(errno));
	fib(20);
	rc = sched_getscheduler(0);
	printf("Now sched: %d\n", rc);
	return 0;
}
开发者ID:yumenoshizuku,项目名称:android-kernel-hw,代码行数:13,代码来源:hw4_c.c

示例10: posix_spawnattr_init

int posix_spawnattr_init(posix_spawnattr_t *attr)
{
  struct sched_param param;
  int ret;

  DEBUGASSERT(attr);

  /* Flags: None */

  attr->flags = 0;

  /* Set the default priority to the same priority as this task */

  ret = sched_getparam(0, &param);
  if (ret < 0)
    {
      return errno;
    }

  attr->priority = param.sched_priority;

  /* Set the default scheduler policy to the policy of this task */

  attr->policy = sched_getscheduler(0);

  /* Empty signal masek */

  attr->sigmask = 0;

  /* Default stack size */

  attr->stacksize = TASK_SPAWN_DEFAULT_STACKSIZE;
  return OK;
}
开发者ID:nsrango,项目名称:Firmware,代码行数:34,代码来源:lib_psa_init.c

示例11: get_sched_policy

int get_sched_policy(int tid, SchedPolicy *policy)
{
    if (tid == 0) {
        tid = gettid();
    }
    pthread_once(&the_once, __initialize);

    if (__sys_supports_schedgroups) {
        char grpBuf[32];
        if (getSchedulerGroup(tid, grpBuf, sizeof(grpBuf)) < 0)
            return -1;
        if (grpBuf[0] == '\0') {
            *policy = SP_FOREGROUND;
        } else if (!strcmp(grpBuf, "bg_non_interactive")) {
            *policy = SP_BACKGROUND;
        } else {
            errno = ERANGE;
            return -1;
        }
    } else {
        int rc = sched_getscheduler(tid);
        if (rc < 0)
            return -1;
        else if (rc == SCHED_NORMAL)
            *policy = SP_FOREGROUND;
        else if (rc == SCHED_BATCH)
            *policy = SP_BACKGROUND;
        else {
            errno = ERANGE;
            return -1;
        }
    }
    return 0;
}
开发者ID:Bliss-Elite,项目名称:platform_system_core,代码行数:34,代码来源:sched_policy.c

示例12: policy

// -------------------------------------------------------------------------------------------------
static void* ThreadMainFunction
(
    void* expectedPolicy  ///< The expected Linux scheduling policy (SCHED_IDLE or SCHED_OTHER).
)
// -------------------------------------------------------------------------------------------------
{
    LE_INFO("Checking scheduling policy...");

    int schedPolicy = sched_getscheduler(0);

    if (schedPolicy == -1)
    {
        LE_FATAL("Failed to fetch scheduling policy (error %d).", errno);
    }

    if (expectedPolicy != (void*)(size_t)schedPolicy)
    {
        LE_FATAL("Expected policy %p.  Got %p.", expectedPolicy, (void*)(size_t)schedPolicy);
    }
    else
    {
        LE_INFO("Policy correct.");
    }

    return NULL;
}
开发者ID:legatoproject,项目名称:legato-af,代码行数:27,代码来源:priority.c

示例13: other

void other(){
	original_calloc = (calloc_type)dlsym(RTLD_NEXT, "calloc");
	if(!original_calloc){
		fprintf(stderr, "original calloc can not be resolved\n");
		exit(-1);
	}
	original_malloc = (malloc_type)dlsym(RTLD_NEXT, "malloc");
	if(!original_malloc){
		fprintf(stderr, "original malloc can not be resolved\n");
		exit(-1);
	}
	original_free = (free_type)dlsym(RTLD_NEXT, "free");
	if(!original_free){
		fprintf(stderr, "original free can not be resolved\n");
		exit(-1);
	}
	original_realloc = (realloc_type)dlsym(RTLD_NEXT, "realloc");
	if(!original_realloc){
		fprintf(stderr, "original realloc can not be resolved\n");
		exit(-1);
	}

	fprintf(stderr, "other %p, malloc %p, calloc %p, realloc %p, free %p\n", 
			other, malloc, calloc, realloc, free);
	fprintf(stderr, "other %p, Retrieved malloc %p, calloc %p, realloc %p, \
			free %p\n", other, original_malloc, original_calloc, 
			original_realloc, original_free);

	fprintf(stderr, "SCHED_OTHER: %d\n",
			sched_getscheduler(getpid()) == SCHED_OTHER? 1 : 0);
	fprintf(stderr, "Min %d, Max %d\n", sched_get_priority_min(SCHED_OTHER), 
			sched_get_priority_max(SCHED_OTHER));
	

}
开发者ID:movingname,项目名称:cruiser-psu,代码行数:35,代码来源:effectTest.cpp

示例14: lx_sched_getparam

int
lx_sched_getparam(uintptr_t pid, uintptr_t param)
{
	int	policy, ret;
	pid_t	s_pid;
	lwpid_t	s_tid;

	struct sched_param sp;

	if (((pid_t)pid < 0) || (param == NULL))
		return (-EINVAL);

	if (lx_lpid_to_spair((pid_t)pid, &s_pid, &s_tid) < 0)
		return (-ESRCH);

	/*
	 * If we're attempting to get information on our own process, we can
	 * get data on a per-thread basis; if not, punt and use the specified
	 * pid.
	 */
	if (s_pid == getpid()) {
		if ((ret = pthread_getschedparam(s_tid, &policy, &sp)) != 0)
		    return (-ret);
	} else {
		if (sched_getparam(s_pid, &sp) == -1)
			return (-errno);

		if ((policy = sched_getscheduler(s_pid)) < 0)
			return (-errno);
	}

	return (stol_sparam(policy, &sp, (struct lx_sched_param *)param));
}
开发者ID:lancerus,项目名称:illumos-joyent,代码行数:33,代码来源:sched.c

示例15: main

int main (void) 
{
	struct sched_param shdprm;
	printf ("SCHED_FIFO : from %d to %d\n",
	sched_get_priority_min (SCHED_FIFO), sched_get_priority_max (SCHED_FIFO)); 
	printf ("SCHED_RR : from %d to %d\n",
	sched_get_priority_min (SCHED_RR), sched_get_priority_max (SCHED_RR)); 
	printf ("SCHED_OTHER: from %d to %d\n",
	sched_get_priority_min (SCHED_OTHER), sched_get_priority_max (SCHED_OTHER));
	printf ("Current policy for this proccess: "); 
	switch (sched_getscheduler (0)) 
	{ 
		case SCHED_FIFO:
		printf ("SCHED__FIFO\n"); break;
		case SCHED_RR:
		printf ("SCHED_RR\n"); break;
		case SCHED_OTHER:
		printf ("SCHED_OTHER\n"); break; case -1:
		perror ("SCHED_GETSCHEDULER"); break; default:
		printf ("Unknown policy\n");
	}

	if (sched_getparam (0, &shdprm) == 0) 
	{
		printf ("Current priority for this proccess: %d\n", shdprm.sched_priority);
	} 
	else 
	{
		perror ("SCHED_GETPARAM");
	}

return 0;
}
开发者ID:ejiek,项目名称:OS,代码行数:33,代码来源:priorities.c


注:本文中的sched_getscheduler函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。