Linux Process priority system-set real-time process priority and linux priority

Source: Internet
Author: User

Linux Process priority system-set real-time process priority and linux priority
Preface

The product recently developed has A small bug. The root cause is that process A uses A Real-Time FIFO-based process priority, while process B uses A normal scheduling process priority, process A and process B communicate with each other, process B will be starved to death, and process A cannot work normally. Some information was found during the problem analysis. The following are some special notes.

Three Linux Process Scheduling Policies

(1) SCHED_OTHER, time-based scheduling policy

(2) SCHED_FIFO, real-time scheduling policy, first served

(3) SCHED_RR, real-time scheduling policy, time slice Rotation

As there are many related content, I am also more clear than others. For more detailed content about process scheduling, I suggest reading "deep understanding of Linux kernel". Many content on the Internet is from here, not necessarily better than this book. For more information, see this link.

Https://blog.csdn.net/maximuszhou/article/details/42042161

Process A encountered A bug previously uses the SCHED_FIFO scheduling policy, while process B is not set. The default value is SCHED_OTHER.

How to set as a real-time process

When searching for information, I found a link asking why the FIFO Policy was set, but not as expected. Link to this http://ask.csdn.net/questions/254095

From the code point of view, because the setting method is incorrect, you can directly go to the code and set the Scheduling Policies of processes and threads.

1 # include <stdio. h> 2 # include <stdlib. h> 3 # include <pthread. h> 4 # include <sched. h> 5 6 7 pid_t pid = getpid (); 8 struct sched_param param; 9 param. sched_priority = capacity (SCHED_FIFO); // SCHED_RR10 sched_setscheduler (pid, SCHED_RR, & param) is also available; // you can set the 11 slave (pthread_self (), SCHED_FIFO ); // set the current thread

You can run the top command to check whether the process is successful. If it is rt, the process is a real-time process. If the operation fails, it may be due to permission issues and requires the roo permission.

Adjust process priority

If you do not adjust the scheduling policy, you can also increase the priority of the process, so that the process gets more CPU, especially interactive programs, and the user health check is better. The code is very simple. You only need to call the nice (int n) function. The valid range of n is-20 ~ 19. A smaller value indicates a higher priority. The specific content is not copied and pasted here, but it is more reliable to see "deep understanding of Linux kernel.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.