本文整理汇总了C++中sched_setparam函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_setparam函数的具体用法?C++ sched_setparam怎么用?C++ sched_setparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sched_setparam函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int policy, result;
int result_code = PTS_PASS;
struct sched_param param;
if(sched_getparam(0, ¶m) == -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,¶m);
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,¶m);
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, ¶m) == -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, ¶m);
if (sched_getparam(0, ¶m) != 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, ¶m );
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, ¶m);
if (r == 0) {
param.sched_priority = priority;
r = pthread_setschedparam(os_thread, policy, ¶m);
}
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, ¶m);
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, ¶m) != 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,¶m);
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, ¶m) == -1) {
perror("An error occurs when calling sched_getparam()");
return PTS_UNRESOLVED;
}
result = sched_setparam(1, ¶m);
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, ¶m));
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, ¶m) == -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,¶m);
if (sched_getparam(0, ¶m) != 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(), ¶m);
}
开发者ID:columbia,项目名称:cr-tests,代码行数:7,代码来源:pi.c
示例16: spawn_execattrs
int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
{
struct sched_param param;
DEBUGASSERT(attr);
/* Now set the attributes. Note that we ignore all of the return values
* here because we have already successfully started the task. If we
* return an error value, then we would also have to stop the task.
*/
/* If we are only setting the priority, then call sched_setparm()
* to set the priority of the of the new task.
*/
if ((attr->flags & POSIX_SPAWN_SETSCHEDPARAM) != 0)
{
/* Get the priority from the attrributes */
param.sched_priority = attr->priority;
/* If we are setting *both* the priority and the scheduler,
* then we will call sched_setscheduler() below.
*/
if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0)
{
svdbg("Setting priority=%d for pid=%d\n",
param.sched_priority, pid);
(void)sched_setparam(pid, ¶m);
}
}
/* If we are only changing the scheduling policy, then reset
* the priority to the default value (the same as this thread) in
* preparation for the sched_setscheduler() call below.
*/
else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0)
{
(void)sched_getparam(0, ¶m);
}
/* Are we setting the scheduling policy? If so, use the priority
* setting determined above.
*/
if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0)
{
svdbg("Setting policy=%d priority=%d for pid=%d\n",
attr->policy, param.sched_priority, pid);
(void)sched_setscheduler(pid, attr->policy, ¶m);
}
return OK;
}
开发者ID:WayWingsDev,项目名称:fernvale-nuttx,代码行数:58,代码来源:task_spawnparms.c
示例17: main
int main(int ac, char **av)
{
int lc, i; /* loop counter */
char *msg; /* message returned from parse_opts */
/* parse standard options */
if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
!= (char *)NULL) {
tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
}
/* perform global setup for test */
setup();
/* check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping. */
Tst_count = 0;
for (i = 0; i < TST_TOTAL; ++i) {
if (i == 2) {
param1.sched_priority = 0;
} else {
param1.sched_priority = 1;
}
if ((sched_setscheduler(0, testcases[i].policy,
¶m1)) == -1) {
tst_brkm(TBROK, cleanup, "sched_setscheduler()"
" failed");
}
param.sched_priority = testcases[i].priority;
/*
* Call sched_setparam(2) with pid=0 sothat it will
* set the scheduling parameters for the calling process
*/
TEST(sched_setparam(0, ¶m));
if ((TEST_RETURN == 0) && (verify_priority(i))) {
tst_resm(TPASS, "%s Passed", testcases[i].desc);
} else {
tst_resm(TFAIL|TTERRNO, "%s Failed. sched_setparam()"
" returned %ld",
testcases[i].desc, TEST_RETURN);
}
}
} /* End for TEST_LOOPING */
/* cleanup and exit */
cleanup();
/*NOTREACHED*/ return 0;
} /* End main */
开发者ID:ystk,项目名称:debian-ltp,代码行数:56,代码来源:sched_setparam02.c
示例18: main
int main() {
int new_priority, max_priority, policy, result;
struct sched_param param;
pthread_t tid;
pthread_attr_t attr;
if(sched_getparam(getpid(), ¶m) != 0){
perror("An error occurs when calling sched_getparam()");
pthread_exit((void*)-1);
}
/* Make sure new_priority != old_priority */
policy = sched_getscheduler(getpid());
max_priority = sched_get_priority_max(policy);
new_priority = (param.sched_priority == max_priority) ?
sched_get_priority_min(policy) :
max_priority;
param.sched_priority = new_priority;
if(sched_setparam(getpid(), ¶m) != 0){
perror("An error occurs when calling sched_setparam()");
return PTS_UNRESOLVED;
}
if(pthread_attr_init(&attr) != 0) {
printf("An error occurs when calling pthread_attr_init()");
return PTS_UNRESOLVED;
}
result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
if(result == ENOTSUP) {
printf("Process contention scope threads are not supported. Use System contention schope instead.\n");
result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
// return PTS_UNSUPPORTED;
} else if(result != 0) {
printf("An error occurs when calling pthread_attr_setscope()");
return PTS_UNRESOLVED;
}
if(pthread_create(&tid, &attr, runner, NULL) != 0) {
printf("An error occurs when calling pthread_create()");
return PTS_UNRESOLVED;
}
if(pthread_getschedparam(tid , &policy, ¶m) != 0) {
printf("An error occurs when calling pthread_getschedparam()");
return PTS_UNRESOLVED;
}
pthread_cancel(tid);
if(param.sched_priority == new_priority){
printf("Test PASSED\n");
return PTS_PASS;
}
printf("The threads does not inherit the right param.\n");
return PTS_FAIL;
}
开发者ID:CSU-GH,项目名称:okl4_3.0,代码行数:56,代码来源:21-2.c
示例19: child_process
void child_process(int id){
int i;
struct sched_param param;
if(id == nb_child-1){
param.sched_priority = sched_get_priority_min(SCHED_RR);
sched_setparam(getpid(), ¶m);
}
for(i=0; i<NB_LOOP_CHILD; i++) {
count ++;
}
}
开发者ID:jiezh,项目名称:h5vcc,代码行数:13,代码来源:2-2.c
示例20: main
int main(int ac, char **av)
{
int lc, i;
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;
for (i = 0; i < TST_TOTAL; ++i) {
if (i == 2) {
param1.sched_priority = 0;
} else {
param1.sched_priority = 1;
}
if ((sched_setscheduler(0, testcases[i].policy,
¶m1)) == -1) {
tst_brkm(TBROK, cleanup, "sched_setscheduler()"
" failed");
}
param.sched_priority = testcases[i].priority;
/*
* Call sched_setparam(2) with pid=0 sothat it will
* set the scheduling parameters for the calling process
*/
TEST(sched_setparam(0, ¶m));
if ((TEST_RETURN == 0) && (verify_priority(i))) {
tst_resm(TPASS, "%s Passed", testcases[i].desc);
} else {
tst_resm(TFAIL | TTERRNO,
"%s Failed. sched_setparam()"
" returned %ld", testcases[i].desc,
TEST_RETURN);
}
}
}
/* cleanup and exit */
cleanup();
tst_exit();
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:51,代码来源:sched_setparam02.c
注:本文中的sched_setparam函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论