您已经了解了如何更改进程的优先级,那么对于线程又该如何操作呢?
Now that you know how to change the priority of processes, how do you do this with threads?
它与其进程的优先级没有依赖关系。
进程的优先级和优先值。
您可以使用nice命令调整给定进程的优先级。
Usage of the nice command allows you to adjust the priority of a given process.
负载平衡:调度器会降低那些超出处理器负载能力的进程的优先级。
Load balancing: the scheduler will decrease the priority of any process that generates more load than the processor can handle.
受控制的进程的优先级是由进程在数组中的位置索引决定的。
The priority of a controlled process is determined by its position index in the array.
nice和Renice——这些值可以更改正在运行的进程的优先级。
Nice and Renice — These change the priority of running processes.
进程中运行的具有不同优先级的线程相对于进程的优先级类运行。
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).
在Windows中,您可以使用SetPriorityClass来设置特定进程的优先级等级。
In Windows, you can use SetPriorityClass to set the priority class for the specified process.
其他的一些菜单允许您kill进程(终止进程)或者renice它们(重新调整进程的优先级),请参见图3。
Other menus allow you to either kill processes or renice them (see Figure 3).
注意,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.
但是在某些情况下,可能必须要为这些进程赋予不同的优先级。
In some circumstances, however, these processes may have to be given different priority.
常规用户启动的进程优先级一般是0。
如果派生进程是一个JVM,则JVM的原始线程创建时具有RT优先级。
If the forked process is a JVM, the primordial thread of the JVM is created with an RT priority.
在数组中,放在前面的进程拥有更高的优先级。
A process that is placed earlier in the array has a higher priority.
为了确保重要的进程能够得到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.
bgnice:在后台以更低的优先级运行所有进程。
Bgnice: Run all processes in the background at a lower priority.
不论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命令还可以用来启动具有不同优先级的进程。
The nice command can also be used to start a process with a different priority.
将id设置为0来修改当前进程(或线程)的优先级。
Set id to 0 to change the current process (or thread) priority.
记住,您必须是超级用户才能为进程指定更高的调度优先级,或者说让它们的nice值更低。
Remember that you have to be the superuser to give your processes higher scheduling priority and make them less nice.
记住,您必须是超级用户才能为进程指定更高的调度优先级,或者说让它们的nice值更低。
Remember that you have to be the superuser to give your processes higher scheduling priority and make them less nice.
应用推荐