English 中文(简体)
等级 等同物
原标题:SetPriorityClass equivalent on Linux

我有类似于mon的应用程序,在初始阶段进行一些软盘处理。 为了避免减缓其他任务,我在视窗上做的是:

SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN);

// initialization tasks

SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_END);

// daemon is ready and running at normal priority

AFAIK, on Unices I can calls nice or set priority and reduction the process priority but I can t rise to what it was at process creation (i.e. there s no amount to the second SetPriorityClass in Occupation)less 我请我享有超级用户特权。 难道我没有机会再做一次呢? (我知道,我可以建立一个低优先的初始化线,等待主线完成,但我更愿意避免)

edit: Bonus Point for Equal SetThreadPriority (GetCurrentThread(), PHREED_MODE_BACKGROUND_BEG信息网);SetThreadPriority (GetCurrentread(), PHED_MODE_BACKGROUND_END);

最佳回答

阁下说,你的处理是磁盘密集的,因此使用<条码> nic/代码>的解决办法赢得了笔工作。 <代码>nice处理万国邮联优先准入问题,而不是I/O准入问题。 PROCESS_MODE_BACKGROUND_BEGIN 降低I/O的优先地位和CPU的优先地位,并要求在XP和老板中不存在斜体特征。

控制I/O优先权并非跨越Unices,而是在现代的六氯环己烷中找到解决办法。 页: 1

关键职能电话是ioprio_set, 您必须通过sys calls打电话。 总结:

static int ioprio_set(int which, int who, int ioprio)
{
    return syscall(SYS_ioprio_set, which, who, ioprio);
}

For full example sources,

根据许可,您进入背景模式的有:IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_IDLE,0)IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_BE,7)。 然后顺序应为:

#define IOPRIO_PRIO_VALUE(class, data)  (((class) << IOPRIO_CLASS_SHIFT) | data)

ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_BE,7));
// Do work
ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IO_PRIO_CLASS_BE,4));

请注意,你们许多人没有获准回到你原先的奥尼优先事项,因此,你需要再次获得最佳努力。

问题回答

实际上,如果你拥有一个合理的最近 kernel,则可能有一个解决办法。 在这里,图西人阵说:

In Linux kernels before 2.6.12, an unprivileged process may use setpriority() only to (irreversibly) lower its own or another process’s nice value.

Since kernel 2.6.12, Linux provides the RLIMIT_NICE resource limit, which permits unprivileged processes to increase nice values. An unprivileged process can raise its own nice value to the maximum specified by the formula 20 – rlim_cur, where rlim_cur is the current RLIMIT_NICE soft resource limit.

基本上,你们必须:

  1. Use ulimit -e to set RLIMIT_NICE
  2. Use setpriority as usual

这方面的一个例子

<<>Edit>code>/etc/security/limits.conf/strong>。 增 编

cnicutar    -    nice    -10

www.un.org/Depts/DGACM/index_spanish.htm 使用ulimit

cnicutar@aiur:~$ ulimit -e
30

我们喜欢这一限制,因此我们不会改变它。

http://www.ohchr.org。

cnicutar@aiur:~$ nice -n -10 ls tmp
cnicutar@aiur:~$ 

cnicutar@aiur:~$ nice -n -11 ls tmp
nice: cannot set niceness: Permission denied

<><>>>>>>>>>>>> 优先程度<>/代码>。

#include <stdio.h>
#include <sys/resource.h>
#include <unistd.h>

int main()
{
        int rc;

        printf("We are being nice!
");
        /* set our nice to 10 */
        rc = setpriority(PRIO_PROCESS, 0, 10);
        if (0 != rc) {
                perror("setpriority");
        }

        sleep(1);

        printf("Stop being nice
");
        /* set our nice to -10 */
        rc = setpriority(PRIO_PROCESS, 0, -10);
        if (0 != rc) {
                perror("setpriority");
        }

        return 0;
}

www.un.org/Depts/DGACM/index_spanish.htm 试验方案

cnicutar@aiur:~$ ./nnice 
We are being nice!
Stop being nice
cnicutar@aiur:~$ 

唯一的缺点是,它不能与其他不统一(或者说是Unices<>/em>?

大力降低优先程度,然后回馈:

  1. fork()
  2. CHILD: lower its priority
  3. PARENT: wait for the child (keeping original parent s priority)
  4. CHILD: do the job (in lower priority)
  5. PARENT: continue with original priority after child is finished.

这应当是可使用的解决办法。





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签