The process.kill( pid[,signal] ) is an inbuilt technique in node.js that conveys a message to the cycle, pid (which is the interaction id) and sign are in the string design that is the sign to send.
Syntax:
process.kill(pid[, signal])
Boundaries: This technique acknowledges two boundaries as referenced above and depicted underneath:
- pid: This boundary holds the interaction ID.
- signal: This boundary holds the string design.
- signal names: These are in string design.
- SIGTERM
- SIGINT
- SIGHUP
Note: If no sign is indicated, then, at that point, as a matter of course ‘SIGTERM’ will be the sign.
- ‘SIGTERM’ and ‘SIGINT’ signals have default controllers on non-Windows stages that reset the terminal mode prior to leaving with code 128 + signal number. Assuming one of these signs has an audience introduced, its default conduct on node.js will be taken out.
- ‘SIGHUP’ is produced when the control center window is shut.
Return esteem: The process.kill() strategy will toss a blunder on the off chance that the objective pid isn’t found or doesn’t exist. This technique returns boolean worth 0 assuming that pid exists and can be utilized as a test for the presence of the objective interaction. For window clients, this technique will likewise toss a mistake assuming pid is utilized to kill a gathering of interaction.
Beneath models show the utilization of the process.kill() property in Node.js.
Example 1:
index.js
const displayInfo = () => {
console.log( 'Receiving SIGINT signal in nodeJS.' );
}
process.on( 'SIGINT' , displayInfo);
setTimeout(() => {
console.log( 'Exiting.' );
process.exit(0);
}, 100);
process.kill(process.pid, 'SIGINT' );
|
Run the application:
node index.js
Output:

Example 2:
index.js
const displayInfo = () => {
console.log( 'Acknowledged SIGHUP signal in nodeJS.' );
}
process.on( 'SIGHUP' , displayInfo);
setTimeout(() => {
console.log( 'Exiting.' );
process.exit(0);
}, 100);
process.kill(process.pid, 'SIGHUP' );
|
Run the application:
node index.js
Output:
