您已经了解了如何更改进程的优先级,那么对于线程又该如何操作呢?
Now that you know how to change the priority of processes, how do you do this with threads?
负载平衡:调度器会降低那些超出处理器负载能力的进程的优先级。
Load balancing: the scheduler will decrease the priority of any process that generates more load than the processor can handle.
进程中运行的具有不同优先级的线程相对于进程的优先级类运行。
Threads with different priorities running in the process run relative to the process's priority class.
现在我们可以让CPU 持续忙碌一段时间,我们了解如何设置进程的优先级。
Now that we can keep a CPU busy for a while, we'll see how to set a priority for a process. To summarize what we've learned so far
dwPriorityClass是进程的优先级等级,它可以设置为下列值中的任意一个。
DwPriorityClass is the priority class of the process, and it is set to any of the following values.
不过,在Linux中,普通非实时进程的优先级范围是从- 20(较高的)到+20(较低的)。
But in Linux, the priority range for normal non-real-time processes is from -20 (higher) to + 20 (lower priority).
注意,JCSP以底层线程的优先级机制实现进程的优先级;所以优先级实际的工作方式取决于底层的JVM实现。
Note that JCSP implements process priorities in terms of the underlying thread's priority mechanism; so how the priorities actually work out depends on the underlying JVM implementation.
一旦设置了进程的优先级等级,就可以使用SetThreadPriority在进程的优先级等级内部设置线程的优先级层次。
Once the priority class of the process is set, SetThreadPriority is used to set the priority level of the thread within the priority class of the process.
这个值被决定了线程的绝对优先级,这个绝对优先级是通过API赋值给线程的优先级以及它所在进程的优先级共同计算得到的。
This value is termed the absolute priority of the thread and is calculated from the priority values assigned through the API to both the thread and the process which owns that thread.
您可以为进程指定一个绝对优先级(不是调整值),进程的更改如清单10 所示。
You specify an absolute priority (and not an adjustment) for the process or processes to be changed as shown in Listing 10.
常规用户启动的进程优先级一般是0。
如果派生进程是一个JVM,则JVM的原始线程创建时具有RT优先级。
If the forked process is a JVM, the primordial thread of the JVM is created with an RT priority.
内核使用收集的CPU 使用量数据,可以根据优先级、当前 CPU 使用量和 CPU 限制调度或撤消运行进程。
The CPU usage thus gathered is used by the kernel, which may schedule or de-schedule a process based on its priority, current CPU usage, and CPU limits.
为了确保重要的进程能够得到CPU,这种选择是基于调度优先级 进程的。
To ensure that important processes don't get starved out by CPU hogs, the selection is done based on a scheduling priority.
如果您正好启动了一个进程,但意识到它应该以不同的优先级运行,那么有一种方法可以在启动之后对其进行更改,即使用renice命令。
If you happen to start a process and realize that it should run at a different priority, there is a way to change it after it has started, using the renice command.
不论activity发生什么情况,使用服务可以保证操作至少拥有“服务进程”的优先级。
Using a service guarantees that the operation will have at least "service process" priority, regardless of what happens to the activity.
使用 Linux系统调用setpriority()来设置或者修改普通进程和线程的优先级层次。
The Linux system call setpriority() is used to set or modify priority levels for normal processes and threads.
记住,您必须是超级用户才能为进程指定更高的调度优先级,或者说让它们的nice值更低。
Remember that you have to be the superuser to give your processes higher scheduling priority and make them less nice.
使用renice命令(通过Procmon或者命令行)可以使得系统为给定的进程分配一个更高的或者更低的优先级。
Using the renice command (either through Procmon or from the command line) can cause the system to either assign a higher or lower priority to a given process.
您还可以使用renice命令(前面在介绍Procmon 的图3中对该命令进行了说明),以便动态地为一个运行的进程重新分配优先级。
You can also use the renice command (illustrated previously with Procmon in Figure 3) to dynamically reassign a priority to a running process.
您可以在本文中提供的示例中看到此公平性,其中所有进程都被授予了对服务器的访问,即便是最低的优先级。
You can see that fairness in the example provided in this article, where all processes are given access to the processor-even the lowest priority.
气象数据进程负责把收集到的气象数据放到数据总线上,运行不频繁,是低优先级进程。
The meteorological data gathering task ran as an infrequent, low priority thread, and used the information bus to publish its data.
当一个高优先级进程或者交互式进程发生跳跃时,整个系统的性能就会受到影响。
When a bouncing process happens to be a high priority or interactive process, overall system performance is affected.
探路者号上的进程按照优先级来执行,优先级反映了这些进程的轻重缓急。
Tasks on the Pathfinder spacecraft were executed as threads with priorities that were assigned in the usual manner reflecting the relative urgency of these tasks.
有不同的信号量类:区分优先级,随着程序大小的增长根据活动进行特殊处理(例如,fifo次序,使用多个读进程)。
Have different kinds of semaphore classes: prioritization, specialization based on activity (for example, FIFO ordering, taking advantage of multiple readers) as the program increases in size.
清单1中的ni列展示了调度优先级或者说每个进程的niceness。
The ni column in Listing 1 above, shows the scheduling priority or niceness of each process.
在进行该操作时,您实际上通过更改进程的nice值,从而更改了线程优先级的值(缺省值为40)。
When you do this, you actually change the value of the priority of a thread (default value of 40) by changing the nice value of its process.
使用nice或renice优化调度程序——可帮助您为运行进程分配不同的优先级,以避免占用大量CPU资源。
Tuning scheduler using nice or renice — This helps you to assign different priorities to running processes to prevent CPU hogs.
在这个步骤完成之后,第二级调度器会根据给定的标准Linux优先级挑选进程来执行。
After this is done, the second-level scheduler picks the process to execute given the standard Linux priorities.
在这个步骤完成之后,第二级调度器会根据给定的标准Linux优先级挑选进程来执行。
After this is done, the second-level scheduler picks the process to execute given the standard Linux priorities.
应用推荐