安卓进程优先级调高,可以用下面两个方法,详细如下:
方法一:
ADB命令如下:
adb shell “ps |grep com.example.hellojni” 用来查看PID号
adb shell renice -n -20 17105 (改成具体pid号)
备注:-20 是优先级最高值 。 即使设为-50,它的值也是-20
方法二:
通过在代码里设置优先级,设置为SCHED_FIFO
int32_t policy; pid_t pid = getpid(); sched_param schedImuDataThreadParam; sched_param schedFisheyeDataThreadParam; pthread_getschedparam(mUnpackDataThread.native_handle(), &policy, &schedFisheyeDataThreadParam); schedFisheyeDataThreadParam.sched_priority = sched_get_priority_max(SCHED_FIFO);
if (pthread_setschedparam(mUnpackDataThread.native_handle(), SCHED_FIFO, &schedFisheyeDataThreadParam)){ LOGW("%s:: set mUnpackDataThread param fail %s", FUNCTION, std::strerror(errno)); }
2022年3月4日 上海徐汇
|