LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to make a (user space )process pre emptive? in 2.6 kernel (https://www.linuxquestions.org/questions/programming-9/how-to-make-a-user-space-process-pre-emptive-in-2-6-kernel-689531/)

papunb 12-10-2008 04:23 AM

How to make a (user space )process pre emptive? in 2.6 kernel
 
Hi!
I am writing a program which i dont want the kernel scheduler to preempt before certain time duration. I am using the system call sched_get_priority_max to set the maximum priority. However it is not producing results.
Waiting for some suggestions.

Mnka

jcookeman 12-10-2008 02:07 PM

'sched_get_priority_max' does not set any values. You need to use 'sched_setparam'.

papunb 12-11-2008 04:24 AM

Hi Thanks for the reply.
Even if i use sched_setparam , i can utmost set the schedule policy and the max priority for that policy , but if i am using SCHED_FIFO and suppose there is another process using SCHED_RR, my process may be pre empted for the SCHED_RR running process.. How do i ensure that for a given time slice , my process is not preemted.

papunb 12-11-2008 07:11 AM

The following is what i am trying to do but i am not able to change the priority of the scheduler .. I am only able to change the policy using sched_setscheduler. I have running it in SU.

int sched_setpriority(pid_t pid, int priority)
{
struct sched_param p;
int min_pri, range_pri;
p.sched_priority = priority;
return sched_setscheduler(pid, SCHED_FIFO, &p);
}



int sched_getsched(pid_t pid)
{
return sched_getscheduler(pid);
}

int sched_getpriority(pid_t pid)
{
return getpriority(PRIO_PROCESS, pid);
}

int main ()
{
pid_t proc ;
proc = getpid();
int i, j, s;
i = sched_getsched(proc);
j = sched_getpriority(proc);

printf("My current sched is %d\nMy current pri is %d\n\n", i, j);

s = sched_setpriority(proc, 99);
if(s)
{
perror("Set Priority -- \n");
}

i = sched_getsched(proc);
j = sched_getpriority(proc);
printf("My new sched is %d\nMy new pri is %d\n\n", i, j);

}


All times are GMT -5. The time now is 03:46 PM.