Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set real-time priority for linux processes

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to set real-time priorities for linux processes". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to set real-time priorities for linux processes.

The linux kernel has five scheduling methods:

SCHED_FIFO real-time scheduling strategy, first in first out

SCHED_RR real-time scheduling strategy, robin round

SCHED_OTHER time-sharing scheduling strategy

SCHED_BATCH batch processing

The policy with the lowest SCHED_IDLE priority

The scheduling algorithms of real-time process and time-sharing process are different, which are implemented in rt.c and fair.c respectively. Real-time processes always take precedence over ordinary processes.

Real-time processes determine the order according to real-time priority. On the other hand, the time-sharing process is scheduled according to fully fair distribution (CFS).

There are two strategies for real-time processes, FIFO and RR. The range of real-time priority is [0, MAX_RT_PRIO-1], and the default is [0mem99]. The real-time priority queue is a set of linked lists, each priority corresponds to a linked list, and the linked list corresponding to the high value is executed first.

Once FIFO is in an executable state, it executes until it blocks or releases CPU itself. Can only be preempted by a higher priority process. It is generally used for processes with short latency and is given a higher priority.

RR executes until the time slice runs out or blocks and releases the CPU itself. Can only be preempted by a higher priority process. It is generally used for processes with slightly longer delays and is given a lower priority.

To set the real-time priority, call sched_setscheduler ()

You can also use the linux command chrt. Chrt also calls the function sched_setscheduler ().

Usage:

Chrt-p pid

Chrt-p 1

Output:

Pid 1's current scheduling policy: SCHED_OTHER

Pid 1's current scheduling priority: 0

Chrt-m

Output:

SCHED_OTHER min/max priority: 0/0

SCHED_FIFO min/max priority: 1/99

SCHED_RR min/max priority: 1/99

SCHED_BATCH min/max priority: 0/0

To set scheduling policy to SCHED_FIFO, enter:

# chrt-f-p [1.. 99] {pid}

Set policy to SCHED_FIFO with 50 priority:

# chrt-f-p 50 1024

To set scheduling policy to SCHED_RR, enter:

# chrt-r-p [1.. 99] {pid}

To set policy scheduling policy to SCHED_OTHER, enter:

# chrt-o-p 0 {pid}

# chrt-o-p 0 1024

If the setting is not successful, it may be due to some restrictions.

Http://home.lupaworld.com/home-space-uid-56821-do-blog-id-232810.html

Need to change

Real-time priority (- r) 0

You can change it directly using ulimit-r 99, and it will be reset every time you start up.

If you want to change it permanently, you can change it in / etc/security/limits.conf.

Also authorize the CAP_SYS_NICE capability to the / usr/bin/chrt command, as follows:

Setcap cap_sys_nice=eip / usr/bin/chrt

Otherwise, the following error may occur:

Chrt: failed to set pid 0's policy: Operation not permitted

At this point, I believe you have a deeper understanding of "how to set real-time priorities for linux processes". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report