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


C++ sched_setparam函数代码示例

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


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

示例1: main

int main(){
	int policy, result;
	int result_code = PTS_PASS;
	struct sched_param param;

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

	/* test when sched_ss_max_repl < 1 */
	param.sched_ss_max_repl = 0;	
	result = sched_setparam(0,&param);
	
	if(result != -1) {
		printf("The returned code is not -1 when sched_ss_max_repl < 1.\n");
		result_code = PTS_FAIL;
	} else if(errno == EPERM) {
		printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n");
		result_code = PTS_UNRESOLVED;
	} else if(errno != EINVAL) {
		perror("Unknow error");
		result_code = PTS_FAIL;
	}

	/* test when sched_ss_max_repl > SS_REPL_MAX */
	param.sched_ss_max_repl = SS_REPL_MAX+1;
	result = sched_setparam(0,&param);

	if(result == -1 && errno == EINVAL) {
		if(result_code == PTS_PASS){
			printf("Test PASSED\n");
		}
		return result_code;
	} else if(result != -1) {
		printf("The returned code is not -1 when sched_ss_max_repl > SS_REPL_MAX.\n");
		return PTS_FAIL;
	} else if(errno == EPERM) {
		if(result_code == PTS_FAIL){
			printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n");
			return PTS_FAIL;
		}
		return PTS_UNRESOLVED;
	} else {
	        perror("Unknow error");
		return PTS_FAIL;
	}
	

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

示例2: main

main()
{	struct sched_param p;
	int p1,p2,p3;
			
	p1=fork();	
	
	if (p1==0)
	{	
	p.sched_priority= 70;	sched_setparam(getpid(),&p);
	
	//settinf RT FIFO scheduler with priority 90    
	sched_setscheduler(getpid(),SCHED_FIFO,&p);
	//printf("Master\n");
	execl("p1","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p1 >0)
	{	printf("P1: Writer\n");	}
	else {	printf("fork P1 fail\n");	}

	p2=fork();
	if (p2==0)
	{	p.sched_priority= 70;	
		sched_setparam(getpid(),&p);
	
		//settinf RT FIFO scheduler with priority 90    
		sched_setscheduler(getpid(),SCHED_FIFO,&p);

		execl("p2","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p2>0)
	{	printf("P2: Reader\n");	}
	else {	printf("fork P2 fail\n");	}
	//---------------------------------------------------------------
	p3=fork();	
	
	if (p3==0)
	{	
	p.sched_priority= 70;	sched_setparam(getpid(),&p);
	
	//settinf RT FIFO scheduler with priority 90    
	sched_setscheduler(getpid(),SCHED_FIFO,&p);
	//printf("Master\n");
	execl("p3","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p3 >0)
	{	printf("P3: Reader\n");	}
	else {	printf("fork P3 fail\n");	}
	//---------------------------------------------------------------
}
开发者ID:kaiserfarrell,项目名称:read_and_write,代码行数:49,代码来源:main.c

示例3: main

int main()
{
	int old_priority;
	struct sched_param param;

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

	/* 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_setparam(0, &param);

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

	if (param.sched_priority == old_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("The priority have changed.\n");
		return PTS_FAIL;
	}
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:34,代码来源:23-3.c

示例4: test

int test( void )
{
  pid_t  pid;
  struct sched_param param;
  int    result;

  pid = 0;

  /*
   *  really should use sched_get_priority_min() and sched_get_priority_max()
   */

  param.sched_priority = 0;
#ifdef _POSIX_SPORADIC_SERVER
  param.sched_ss_low_priority = 0;
  param.sched_ss_repl_period.tv_sec = 0;
  param.sched_ss_repl_period.tv_nsec = 0;
  param.sched_ss_init_budget.tv_sec = 0;
  param.sched_ss_init_budget.tv_nsec = 0;
#endif

  result = sched_setparam( pid, &param );

  return result;
}
开发者ID:AlexShiLucky,项目名称:rtems,代码行数:25,代码来源:sched01.c

示例5: main

int main(int argc, char *argv[]) {
	int i = 0;
	struct sched_param par;
    //int str;

	int arg = atoi(argv[1]);
	int newPriority = atoi(argv[2]);
	printf("jestem w zadaniu 5a wywolanym przez funkcje execl, arg: %d \n", arg);

	int status = getpid();

	sched_getparam(0,&par);
    par.sched_priority = newPriority;
    sched_setparam(0,&par);
	//sched_setscheduler(0,SCHED_FIFO,&par);

	for ( i = 0; i < arg ; i++ ){
	          printf ( "Proces potomny(priorytet %d) o pid %d krok %d\n",par.sched_priority, getpid(), i + 1 );

	          sleep(1);
	   }
   exit(status);//chyba nie potrzebne
	//exit();

}
开发者ID:tomekl007,项目名称:RTSexercises,代码行数:25,代码来源:Zadanie5a.c

示例6: port_thread_set_priority

int port_thread_set_priority(osthread_t os_thread, int priority)
{
/*  Dhruwat - haiku porting - start */
/*#if defined(FREEBSD)*/
#if defined(FREEBSD) || defined(HAIKU)
/*  Dhruwat - haiku porting - start */
/*TODO - check if it ok for Haiku */
    /* Not sure why we don't just use this on linux? - MRH */
    struct sched_param param;
    int policy;
    int r = pthread_getschedparam(os_thread, &policy, &param);
    if (r == 0) {
        param.sched_priority = priority;
        r = pthread_setschedparam(os_thread, policy, &param);
    }
    return r;
#else
    // setting thread priority on linux is only supported for current thread
    if (os_thread == pthread_self()) {
        int r;
        struct sched_param param;
        pid_t self = gettid();
        param.sched_priority = priority;
        r = sched_setparam(self, &param);
        return r ? errno : 0;
    } else {
        // setting other thread priority not supported on linux
        return 0;
    }
#endif
}
开发者ID:unitedroad,项目名称:harmony-for-haiku,代码行数:31,代码来源:thread_os.c

示例7: main

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

	if (sched_getparam(0, &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		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;

	result = sched_setparam(0,&param);

	if (result == -1 && errno == EINVAL) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (result != -1) {
		printf("The returned code is not -1.\n");
		return PTS_FAIL;
	} else if (errno == EPERM) {
		printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n");
		return PTS_UNRESOLVED;
	} else {
	        perror("Unknown error");
       	        return PTS_FAIL;
	}
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:32,代码来源:25-3.c

示例8: main

int main(){
	int result;
        struct sched_param param;

        /* We assume process Number 1 is created by root */
        /* and can only be accessed by root */ 
        /* This test should be run under standard user permissions */
        if (getuid() == 0) {
	  	if (set_nonroot() != 0) {
			  printf("Cannot run this test as non-root user\n");	
                return PTS_UNTESTED;
        }
        }

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

	result = sched_setparam(1, &param);

	if(result == -1 && errno == EPERM) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if(errno != EPERM) {
	        perror("errno is not EPERM");
		return PTS_FAIL;
	} else {
		printf("The returned code is not -1.\n");
		return PTS_FAIL;
	}
}
开发者ID:ystk,项目名称:debian-ltp,代码行数:32,代码来源:26-1.c

示例9: main

int main(int ac, char **av)
{

	int lc;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * Call sched_setparam(2) with pid=0 sothat it will
		 * set the scheduling parameters for the calling process
		 */
		TEST(sched_setparam(0, &param));

		if (TEST_RETURN == 0) {
			tst_resm(TPASS, "sched_setparam() returned %ld",
				 TEST_RETURN);
		} else {
			tst_resm(TFAIL|TTERRNO, "Test Failed, sched_setparam()"
				 "returned %ld", TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:33,代码来源:sched_setparam01.c

示例10: rtaudio_set_priority

static PyObject *
rtaudio_set_priority(PyObject *obj, PyObject *args)
{
  int priority;
  if(!PyArg_ParseTuple(args, "i", &priority))
    return NULL;

#if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__)
  struct sched_param schp = { 0 };
  int ret;
  schp.sched_priority = priority;

  ret = sched_setparam(0, &schp);
  if(ret == -1)
    {
      PyErr_Format(RtAudioError, strerror(errno));
      return NULL;
    }

#elif defined(__MACOSX_CORE__)

  struct sched_param sp;
 
  memset(&sp, 0, sizeof(struct sched_param));
  sp.sched_priority=priority;
  if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp)  == -1) 
    {
      PyErr_SetString(RtAudioError, strerror(errno));
      return NULL;
    }

#endif
  Py_RETURN_NONE;
}
开发者ID:RikVerschueren,项目名称:AccordionMega,代码行数:34,代码来源:rtaudiomodule.cpp

示例11: lx_sched_setparam

long
lx_sched_setparam(uintptr_t pid, uintptr_t param)
{
	int	err, policy;
	pid_t	s_pid;
	lwpid_t	s_tid;
	struct lx_sched_param lp;
	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 (s_pid == getpid()) {
		struct sched_param dummy;

		if ((err = pthread_getschedparam(s_tid, &policy, &dummy)) != 0)
			return (-err);
	} else
		if ((policy = sched_getscheduler(s_pid)) < 0)
			return (-errno);

	lx_debug("sched_setparam(): current policy %d", policy);

	if (uucopy((void *)param, &lp, sizeof (lp)) != 0)
		return (-errno);

	/*
	 * In Linux, the only valid SCHED_OTHER scheduler priority is 0
	 */
	if ((policy == SCHED_OTHER) && (lp.lx_sched_prio != 0))
		return (-EINVAL);

	if ((err = ltos_sparam(policy, (struct lx_sched_param *)&lp,
	    &sp)) != 0)
		return (err);

	/*
	 * Check if we're allowed to change the scheduler for the process.
	 *
	 * If we're operating on a thread, we can't just call
	 * pthread_setschedparam() because as all threads reside within a
	 * single Solaris process, Solaris will allow the modification
	 *
	 * If we're operating on a process, we can't just call sched_setparam()
	 * because Solaris will allow the call to succeed if the scheduler
	 * parameters do not differ from those being installed, but Linux wants
	 * the call to fail.
	 */
	if ((err = check_schedperms(s_pid)) != 0)
		return (err);

	if (s_pid == getpid())
		return (((err = pthread_setschedparam(s_tid, policy, &sp)) != 0)
		    ? -err : 0);

	return ((sched_setparam(s_pid, &sp) == -1) ? -errno : 0);
}
开发者ID:maosi66,项目名称:illumos-joyent,代码行数:60,代码来源:sched.c

示例12: rtSchedNativeRestore

/**
 * Restores scheduling attributes.
 * Most of this won't work right, but anyway...
 */
static void rtSchedNativeRestore(PSAVEDPRIORITY pSave)
{
    setpriority(PRIO_PROCESS, 0, pSave->iPriority);
    sched_setscheduler(0, pSave->iPolicy, &pSave->SchedParam);
    sched_setparam(0, &pSave->SchedParam);
    pthread_setschedparam(pthread_self(), pSave->iPthreadPolicy, &pSave->PthreadSchedParam);
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:11,代码来源:sched-linux.cpp

示例13: main

int main() {
	int old_priority;
	struct sched_param param;

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

	param.sched_ss_max_repl = 0;
	param.sched_priority++;
	sched_setparam(0,&param);

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

	if (param.sched_priority == old_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("The priority have changed.\n");
		return PTS_FAIL;
	}

}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:28,代码来源:23-4.c

示例14: set_sched_status

int set_sched_status(int policy, int priority)
{
    int ret, min_prio, max_prio;
    struct sched_param sp;
    max_prio = sched_get_priority_max(policy);
    min_prio = sched_get_priority_min(policy);
    if (max_prio == -1 || min_prio == -1)
        whine("Cannot determine scheduler prio limits!\n");
    else if (priority < min_prio)
        priority = min_prio;
    else if (priority > max_prio)
        priority = max_prio;
    memset(&sp, 0, sizeof(sp));
    sp.sched_priority = priority;
    ret = sched_setscheduler(getpid(), policy, &sp);
    if (ret) {
        whine("Cannot set scheduler policy!\n");
        return -EINVAL;
    }
    ret = sched_setparam(getpid(), &sp);
    if (ret) {
        whine("Cannot set scheduler prio!\n");
        return -EINVAL;
    }
    return 0;
}
开发者ID:candinico,项目名称:netsniff-ng,代码行数:26,代码来源:xsys.c

示例15: set_my_static_priority

int set_my_static_priority(int prio)
{
	struct sched_param param;

	param.sched_priority = prio;
	return sched_setparam(gettid(), &param);
}
开发者ID:columbia,项目名称:cr-tests,代码行数:7,代码来源:pi.c


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