背景
嵌入式平台比较青睐busybox
提高设备安全性
其中内建了chrt
可以方便的修改调度优先策略
问题
实际使用过程中发现chrt不能统一修改全部thread的优先级
chrt
chrt [ OPTIONS ] [ PRIO ] [ PID | PROG [ ARGS ]]
Manipulate real-time attributes of a process
Options:
-p Operate on pid
-r Set scheduling policy to SCHED_RR
-f Set scheduling policy to SCHED_FIFO
-o Set scheduling policy to SCHED_OTHER
-m Show min and max priorities
原因是缺少-a
参数无法修改PID下全部的TID默认只修改main函数产生的main thread
实现
既然无法自动修改,寻求手动修改方法,声明一个shell function达成效果。
# use self-defined function
promote(){ for i in `ls /proc/${1}/task/`;do chrt -r -p 99 ${i};done; }
效果输出
# promote 4539
pid 4539's current scheduling policy: SCHED_OTHER
pid 4539's current scheduling priority: 0
pid 4539's new scheduling policy: SCHED_RR
pid 4539's new scheduling priority: 99
pid 4540's current scheduling policy: SCHED_OTHER
pid 4540's current scheduling priority: 0
pid 4540's new scheduling policy: SCHED_RR
pid 4540's new scheduling priority: 99
pid 4541's current scheduling policy: SCHED_OTHER
pid 4541's current scheduling priority: 0
pid 4541's new scheduling policy: SCHED_RR
pid 4541's new scheduling priority: 99
pid 4542's current scheduling policy: SCHED_OTHER
pid 4542's current scheduling priority: 0
pid 4542's new scheduling policy: SCHED_RR
pid 4542's new scheduling priority: 99
pid 4543's current scheduling policy: SCHED_OTHER
pid 4543's current scheduling priority: 0
pid 4543's new scheduling policy: SCHED_RR
pid 4543's new scheduling priority: 99
pid 4544's current scheduling policy: SCHED_OTHER
pid 4544's current scheduling priority: 0
pid 4544's new scheduling policy: SCHED_RR
pid 4544's new scheduling priority: 99
pid 4551's current scheduling policy: SCHED_OTHER
pid 4551's current scheduling priority: 0
pid 4551's new scheduling policy: SCHED_RR
pid 4551's new scheduling priority: 99
pid 4559's current scheduling policy: SCHED_OTHER
pid 4559's current scheduling priority: 0
pid 4559's new scheduling policy: SCHED_RR
pid 4559's new scheduling priority: 99
pid 4560's current scheduling policy: SCHED_OTHER
pid 4560's current scheduling priority: 0
pid 4560's new scheduling policy: SCHED_RR
pid 4560's new scheduling priority: 99
pid 4561's current scheduling policy: SCHED_OTHER
pid 4561's current scheduling priority: 0
pid 4561's new scheduling policy: SCHED_RR
pid 4561's new scheduling priority: 99
pid 4562's current scheduling policy: SCHED_OTHER
pid 4562's current scheduling priority: 0
pid 4562's new scheduling policy: SCHED_RR
pid 4562's new scheduling priority: 99
pid 4563's current scheduling policy: SCHED_OTHER
pid 4563's current scheduling priority: 0
pid 4563's new scheduling policy: SCHED_RR
pid 4563's new scheduling priority: 99
pid 4564's current scheduling policy: SCHED_OTHER
pid 4564's current scheduling priority: 0
pid 4564's new scheduling policy: SCHED_RR
pid 4564's new scheduling priority: 99
pid 4565's current scheduling policy: SCHED_OTHER
pid 4565's current scheduling priority: 0
pid 4565's new scheduling policy: SCHED_RR
pid 4565's new scheduling priority: 99
pid 4566's current scheduling policy: SCHED_OTHER
pid 4566's current scheduling priority: 0
pid 4566's new scheduling policy: SCHED_RR
pid 4566's new scheduling priority: 99
pid 4567's current scheduling policy: SCHED_OTHER
pid 4567's current scheduling priority: 0
pid 4567's new scheduling policy: SCHED_RR
pid 4567's new scheduling priority: 99
pid 4568's current scheduling policy: SCHED_OTHER
pid 4568's current scheduling priority: 0
pid 4568's new scheduling policy: SCHED_RR
pid 4568's new scheduling priority: 99
pid 4569's current scheduling policy: SCHED_OTHER
pid 4569's current scheduling priority: 0
pid 4569's new scheduling policy: SCHED_RR
pid 4569's new scheduling priority: 99
pid 4570's current scheduling policy: SCHED_OTHER
pid 4570's current scheduling priority: 0
pid 4570's new scheduling policy: SCHED_RR
pid 4570's new scheduling priority: 99
参考
gettid(2) - Linux manual page
busybox(1): Swiss Army Knife of Embedded - Linux man page