会经常改变过程优先级有副作用

时间:2017-03-31 17:26:32

标签: unix process

我在做嵌入式系统编程。 默认情况下,我们的进程设置为更高的优先级,但是对于某些操作,例如调用shell命令,写入文件。我想降低它的优先级,然后再次提升它。所以它有点像一对函数调用:" setdefaultpriority"和"提高优先级"。

在我们的过程中有很多shell命令调用。在一个文件中,我可能需要调用几十对" setdefault ..."和"改善.."

我的问题是,在一个过程中如此多的优先操作会产生什么不良影响?

1 个答案:

答案 0 :(得分:0)

非根进程中的

(done) =>只能上升(降低优先级),永不停机。

在执行shell命令之前,您可以做的是降低子进程中的进程优先级。

setpriority

//errror checks ommited #include <sys/resource.h> #include <sys/time.h> #include <stdio.h> #include <unistd.h> #include <assert.h> #include <sys/wait.h> int main() { pid_t pid; pid=fork(); assert(pid>=0); if (!pid){ execlp("nice", "nice", (char*)0); _exit(1); } wait(0); pid=fork(); if (!pid){ setpriority(PRIO_PROCESS, 0, 10); execlp("nice", "nice", (char*)0); _exit(1); } } /* should print: 0 10 */ setpriority的费用相比,与fork一样简单的系统调用的性能开销应该可以忽略不计。