All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] setting priority
@ 2009-11-05  9:20 tarek ben ali
  2009-11-05  9:44 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 4+ messages in thread
From: tarek ben ali @ 2009-11-05  9:20 UTC (permalink / raw)
  To: Xenomai help, xenomai

[-- Attachment #1: Type: text/plain, Size: 3538 bytes --]

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, &param) == -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, &param);

                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, &param) != 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;
}

[-- Attachment #2: Type: text/html, Size: 4155 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-05 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-05  9:20 [Xenomai-core] setting priority tarek ben ali
2009-11-05  9:44 ` Gilles Chanteperdrix
2009-11-05 13:38   ` tarek ben ali
2009-11-05 13:42     ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.