setting priority
I'm trying to set priority to a specified process on including its PID,the code below is running BUT after allocating priority and policy the output of "top" commande seems not changing(the priority of the process specified is still the same).Is there any explanation please?
#include <sched.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include "posixtest.h"
struct unique {
int value;
char *name;
} sym[] = { {
SCHED_FIFO, "SCHED_FIFO"
},
{
SCHED_RR, "SCHED_RR"
},//#if defined(_POSIX_SPORADIC_SERVER) ||defined(_POSIX_THREAD_SPORADIC_SERVER)
// {
// SCHED_SPORADIC,"SCHED_SPORADIC"
// },
//#endif
{
SCHED_OTHER, "SCHED_OTHER"
},
{
0, 0
}
};int main(int argc, char **argv)
{
int tmp, policy, priority,pid, result = PTS_PASS,old_priority,
old_policy;
struct sched_param param;
struct unique *tst;
printf("Set the PID of the process you want to modifie its priority:
");
scanf("%d",&pid);
if(sched_getparam(pid, ¶m) == -1) {
perror("An error occurs when calling sched_getparam()");
return PTS_UNRESOLVED;
}
old_priority = param.sched_priority;
old_policy = sched_getscheduler(pid);
printf("The current priority set is %d and the the current policy is%d \n",old_priority,old_policy);
printf("******************************************************************\n
");
if(old_policy == -1) {
perror("An error occurs when calling sched_getscheduler()");
return PTS_UNRESOLVED;
}
tst = sym;
while (tst->name) {
fflush(stderr);
printf("Policy: %s\n", tst->name);
fflush(stdout);
policy = tst->value;
//priority = ( sched_get_priority_min(policy) +
// sched_get_priority_max(policy) ) / 2;
priority=1;
param.sched_priority = priority;
tmp = sched_setscheduler(pid, policy, ¶m);
if(tmp == -1 || errno != 0) {
if(errno == EPERM){
printf(" The process do not have permission
to change its own scheduler\n Try to run this test as root.\n");
} else {
printf(" Error calling sched_setscheduler()
for %s policy\n", tst->name);
}
if(result != PTS_FAIL) result = PTS_UNRESOLVED;
tst++;
continue;
}
if(sched_getparam(pid, ¶m) != 0) {
perror("Error calling sched_getparam()");
return PTS_UNRESOLVED;
}
if(policy != sched_getscheduler(pid)){
printf(" sched_setscheduler() does not set the
policy to %s.\n", tst->name);
result = PTS_FAIL;
}
if(priority != param.sched_priority) {
printf(" sched_setscheduler() does not set the
right param for %s policy.\n", tst->name);
result = PTS_FAIL;
}
tst++;
}
if(result == PTS_PASS)
printf("Test PASSED\n");
return result;
}Quoted 5 lines · tarek ben ali
I'm trying to set priority to a specified process on including its PID,the code below is running BUT after allocating priority and policy the output of "top" commande seems not changing(the priority of the process specified is still the same).Is there any explanation please?
Here we know a few things or two about Xenomai, not about top. So, I have no idea. Now, if you are trying to set the priority of a Xenomai thread using Xenomai posix skin, as I already told you in the previous mail, you have to use services described here, not sched_setscheduler:
http://www.xenomai.org/documentation/xenomai-2.4/html/api/group__posix__sched.html
Signature · 1 line
Gilles
2009/11/5 Gilles Chanteperdrix <>
Gilles would you like to take a look on this please:
#include <sched.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
struct sched_param param;
param.sched_priority = 99;
sched_setscheduler(0, SCHED_FIFO, ¶m);
while(1) sleep(1);
exit(0);
}-->
/root> ./t&
/root> ps l
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND 4 0 2984 2881 -100 - 1548 284 - SN pts/0 0:00 ./t 0 0 2988 2881 20 0 2348 740 - R+ pts/0 0:00 ps l
the process has no longer a priority due to the set of SCHED_FIFO ,moreover it's marked as an RT task.
The question is when defining a PID of process running(ex:3760 firefox ) this result is lost!!
Quoted 4 lines · tarek ben ali
2009/11/5 Gilles Chanteperdrix <>
Gilles would you like to take a look on this please:
No. This is not related to Xenomai. At all.
Signature · 1 line
Gilles