Книга: Embedded Linux Primer: A Practical, Real-World Approach
17.3.3. Creating a Real-Time Process
17.3.3. Creating a Real-Time Process
You can designate a process as real time by setting a process attribute that the scheduler uses as part of its scheduling algorithm. Listing 17-4 shows the general method.
Listing 17-4. Creating a Real-Time Process
#include <sched.h>
#define MY_RT_PRIORITY MAX_USER_RT_PRIO /* Highest possible */
int main(int argc, char **argv) {
...
int rc, old_scheduler_policy;
struct sched_param my_params;
...
/* Passing zero specifies caller's (our) policy */
old_scheduler_policy = sched_getscheduler(0);
my_params.sched_priority = MY_RT_PRIORITY;
/* Passing zero specifies callers (our) pid */
rc = sched_setscheduler(0, SCHED_RR, &my_params);
if (rc == -1) handle_error();
...
}
This code snippet does two things in the call to sched_setscheduler(). It changes the scheduling policy to SCHED_RR and raises its priority to the maximum possible on the system. Linux supports three scheduling policies:
• SCHED_OTHER : Normal Linux process, fairness scheduling
• SCHED_RR : Real-time process with a time slicethat is, if it does not block, it is allowed to run for a given period of time determined by the scheduler
• SCHED_FIFO : Real-time process that runs until it either blocks or explicitly yields the processor, or until another higher-priority SCHED_FIFO process becomes runnable
The man page for sched_setscheduler provides more detail on the three different scheduling policies.
- 17.3. Real-Time Kernel Patch
- 2.2.1 Creation
- Ограничение времени ожидания для транзакций (Lock timeout)
- DEADLOCK TIMEOUT
- CONNECTION TIMEOUT
- Introduction to Microprocessors and Microcontrollers
- Timestamp request
- Realm match
- Creating CDs from the Command Line
- Конкурентный бенчмаркинг в GE Real Estate
- Chapter 2 Building and Deploying a Run-Time Image
- Using the kill Command to Control Processes