• Node.js Video Tutorials

Node.js - os.getPriority() Method



The Node.js os.getPriority() method returns an integer specifying the scheduling priority of the process which is specified by the PID (Process ID). It returns an integer value between 0 (highest priority) and 19 (lowest priority). This value can be used to adjust the scheduling priority of a given process or thread, allowing it to receive more CPU time than other processes on the system.

Below are the priority constants that are provided by Node.js −

  • PRIORITY_LOW − This is the lowest process scheduling priority. On Windows, this corresponds to IDLE PRIORITY CLASS, and on all other platforms, it has a nice value of 19.

  • PRIORITY_BELOW_NORMAL − On windows, this corresponds to BELOW_NORMAL_PRIORITY_CLASS, and on all other platforms, it has a nice value of 10.

  • PRIORITY_NORMAL − This is the default process scheduling priority and this corresponds to NORMAL_PRIORITY_CLASS on windows. 0 is a nice value on all other platforms.

  • PRIORITY_ABOVE_NORMAL − This corresponds to ABOVE_NORMAL_PRIORITY_CLASS on windows and all other platforms, it has a nice value of -7.

  • PRIORITY_HIGH − On windows, this corresponds to HIGH_PRIORITY_CLASS, and on all other platforms, it has a nice value of -14.

  • PRIORITY_HIGHEST − This is the highest process scheduling priority and this corresponds to REALTIME_PRIORITY_CLASS on windows. -20 is a nice value on all other platforms.

Syntax

Following is the syntax of the Node.js os.getPriority() method −

os.getPriority([pid])

Parameters

  • pid − This is a process ID passed as an integer. If the process ID is not provided or it is 0, then the priority of the current process is returned.

Return value

This method will return an integer that represents the scheduling priority of a process as specified by the pid. The scheduling priority of the current process is returned if the value of the process ID is 0.

Example

If no parameters are passed to the os.getPriority() method, the scheduling priority of the current process will be returned.

In the following example, we are trying to return an integer indicating the priority of the current process.

const os = require('os');

console.log(os.getPriority());

Output

After executing the above program, the os.getPriority() method will return the priority of the current process.

0
nodejs_os_module.htm
Advertisements