- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
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