本文整理汇总了C++中sched_getparam函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_getparam函数的具体用法?C++ sched_getparam怎么用?C++ sched_getparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sched_getparam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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;
}
}
示例3: 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, ¶m);
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, ¶m);
if (!rc)
goto unresolved;
label = "sched_getparam()";
rc = sched_getparam(pid, ¶m);
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;
}
示例4: 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(), ¶m) == -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, ¶m);
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(), ¶m) != 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;
}
示例5: main
int main(){
int policy, result;
int old_priority, old_policy, new_policy;
struct sched_param param;
if(sched_getparam(getpid(), ¶m) != 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, ¶m);
if(sched_getparam(getpid(), ¶m) != 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;
}
示例6: main
int main(void)
{
int invalid_priority;
int old_priority, old_policy, new_policy;
struct sched_param param;
if (sched_getparam(getpid(), ¶m) != 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, ¶m);
if (sched_getparam(getpid(), ¶m) != 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;
}
示例7: main
int main() {
int max_priority, old_priority, old_policy, new_policy;
struct sched_param param;
if (sched_getparam(getpid(), ¶m) == -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, ¶m);
if (sched_getparam(getpid(), ¶m) != 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;
}
}
示例8: setRealTimeScheduling
/*------------------------------------------------------------------------------
* Set POSIX real-time scheduling
*----------------------------------------------------------------------------*/
void
DarkIce :: setRealTimeScheduling ( void ) throw ( Exception )
{
// Only if the OS has the POSIX real-time scheduling functions implemented.
#if defined( HAVE_SCHED_GETSCHEDULER ) && defined( HAVE_SCHED_GETPARAM )
int high_priority;
struct sched_param param;
/* store the old scheduling parameters */
if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
}
if ( sched_getparam( 0, ¶m) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
origSchedPriority = param.sched_priority;
/* set SCHED_FIFO with max - 1 priority or user configured value */
if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
}
reportEvent( 8, "scheduler high priority", high_priority);
if (realTimeSchedPriority > high_priority) {
param.sched_priority = high_priority - 1;
} else {
param.sched_priority = realTimeSchedPriority;
}
if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) {
reportEvent( 1,
"Could not set POSIX real-time scheduling, "
"this may cause recording skips.\n"
"Try to run darkice as the super-user.");
} else {
/* ask the new priortiy and report it */
if ( sched_getparam( 0, ¶m) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
reportEvent( 1,
"Using POSIX real-time scheduling, priority",
param.sched_priority );
}
#else
reportEvent( 1, "POSIX scheduling not supported on this system, "
"this may cause recording skips");
#endif // HAVE_SCHED_GETSCHEDULER && HAVE_SCHED_GETPARAM
}
示例9: setRealTimeScheduling
/*------------------------------------------------------------------------------
* Set POSIX real-time scheduling, if super-user
*----------------------------------------------------------------------------*/
void
DarkIce :: setRealTimeScheduling ( void ) throw ( Exception )
{
uid_t euid;
euid = geteuid();
if ( euid == 0 ) {
int high_priority;
struct sched_param param;
/* store the old scheduling parameters */
if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
}
if ( sched_getparam( 0, ¶m) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
origSchedPriority = param.sched_priority;
/* set SCHED_FIFO with max - 1 priority */
if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
}
reportEvent( 8, "scheduler high priority", high_priority);
param.sched_priority = high_priority - 1;
if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
}
/* ask the new priortiy and report it */
if ( sched_getparam( 0, ¶m) == -1 ) {
throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
}
reportEvent( 1,
"Using POSIX real-time scheduling, priority",
param.sched_priority );
} else {
reportEvent( 1,
"Not running as super-user, unable to use POSIX real-time scheduling" );
reportEvent( 1,
"It is recommended that you run this program as super-user");
}
}
示例10: main
int main(int argc, char **argv)
{
struct sched_param param;
int result = -1;
param.sched_priority = -1;
result = sched_getparam(0, ¶m);
if (result == 0 && param.sched_priority != -1 && errno == 0) {
printf("Test PASSED\n");
return PTS_PASS;
}
if (errno != 0) {
perror("Unexpected error");
return PTS_FAIL;
}
if (result != 0) {
printf("returned code is not zero.\n");
return PTS_FAIL;
} else {
perror("Unresolved test error");
return PTS_UNRESOLVED;
}
printf("This code should not be executed.\n");
return PTS_UNRESOLVED;
}
示例11: go_realtime
int go_realtime(void)
{
int max_pri;
struct sched_param sp;
if (sched_getparam(0, &sp)) {
perror("sched_getparam");
return -1;
}
max_pri = sched_get_priority_max(SCHED_FIFO);
sp.sched_priority = REALTIME_PRIORITY;
if (sp.sched_priority > max_pri) {
fprintf(stderr, "Invalid priority (maximum %d)\n", max_pri);
return -1;
}
if (sched_setscheduler(0, SCHED_FIFO, &sp)) {
perror("sched_setscheduler");
return -1;
}
return 0;
}
示例12: main
int
main(int argc, char *argv[])
{
int j, pol;
struct sched_param sp;
for (j = 1; j < argc; j++) {
pol = sched_getscheduler(getLong(argv[j], 0, "pid"));
if (pol == -1)
errExit("sched_getscheduler");
if (sched_getparam(getLong(argv[j], 0, "pid"), &sp) == -1)
errExit("sched_getparam");
printf("%s: %-5s ", argv[j],
(pol == SCHED_OTHER) ? "OTHER" :
(pol == SCHED_RR) ? "RR" :
(pol == SCHED_FIFO) ? "FIFO" :
#ifdef SCHED_BATCH /* Linux-specific */
(pol == SCHED_BATCH) ? "BATCH" :
#endif
#ifdef SCHED_IDLE /* Linux-specific */
(pol == SCHED_IDLE) ? "IDLE" :
#endif
"???");
printf("%2d\n", sp.sched_priority);
}
exit(EXIT_SUCCESS);
}
示例13: 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;
}
}
示例14: 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;
param.sched_priority = sched_get_priority_max(SCHED_SPORADIC);
result = sched_setscheduler(0, SCHED_SPORADIC, ¶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 policy.\nTry to launch this test as root.\n");
return PTS_UNRESOLVED;
}
perror("Unknow error");
return PTS_FAIL;
}
示例15: raise_priority
static int raise_priority()
{
int max_pri;
struct sched_param sp;
fprintf(stderr, "Setting scheduler priority...\n");
if (sched_getparam(0, &sp)) {
perror("sched_getparam");
return -1;
}
max_pri = sched_get_priority_max(SCHED_FIFO);
sp.sched_priority = REALTIME_PRIORITY;
if (sp.sched_priority > max_pri) {
fprintf(stderr, "Invalid scheduling priority (maximum %d).\n", max_pri);
return -1;
}
if (sched_setscheduler(0, SCHED_FIFO, &sp)) {
perror("sched_setscheduler");
fprintf(stderr, "Failed to set scheduler. Run as root otherwise you "
"may get wow and skips!\n");
}
return 0;
}