Node.js process.kill() Method Last Updated : 17 Jan, 2022 Comments Improve Suggest changes Like Article Like Report The process.kill( pid[,signal] ) is an inbuilt method of node.js which sends a signal to the process, pid (which is the process id) and signal is in the string format that is the signal to send. Syntax : process.kill(pid[, signal]) Parameters: This method accepts two parameters as mentioned above and described below: pid: This parameter holds the process ID. signal: This parameter holds the string format. signal names : These are in string format . SIGTERM SIGINT SIGHUP Note : If no signal specified, then by default 'SIGTERM' will be the signal. 'SIGTERM' and 'SIGINT' signals have default handlers on non-Windows platforms that reset the terminal mode before exiting with code 128 + signal number. If one of these signals has a listener installed, its default behavior on node.js will be removed.'SIGHUP' is generated when the console window is closed. Return value : The process.kill() method will throw an error if the target pid is not found or doesn't exist. This method returns boolean value 0 if pid exists and can be used as a test for the existence of the target process. For window users, this method will also throw an error if pid is used to kill a group of process. Below examples illustrate the use of process.kill() property in Node.js: Example 1: index.js // Node.js program to demonstrate the // process.kill(pid[, signal]) method // Printing process signal acknowledged const displayInfo = () => { console.log('Receiving SIGINT signal in nodeJS.'); } // Initiating a process process.on('SIGINT', displayInfo); setTimeout(() => { console.log('Exiting.'); process.exit(0); }, 100); // kill the process with pid and signal = 'SIGINT' process.kill(process.pid, 'SIGINT'); Command to run : node index.js Output : Example 2 : index.js // Node.js program to demonstrate the // process.kill(pid[, signal]) method // Printing process signal acknowledged const displayInfo = () => { console.log('Acknowledged SIGHUP signal in nodeJS.'); } // Initiating a process process.on('SIGHUP', displayInfo); setTimeout(() => { console.log('Exiting.'); process.exit(0); }, 100); // kill the process with pid and signal = 'SIGHUP' process.kill(process.pid, 'SIGHUP'); Command to run : node index.js Output : Reference : https://nodejs.org/api/process.html#process_process_kill_pid_signal Comment More infoAdvertise with us Next Article Node.js process.kill() Method jt9999709701 Follow Improve Article Tags : JavaScript Web Technologies Node.js Node.js-Methods NodeJS-Process +1 More Similar Reads Node.js process.exit() Method The process.exit() method is used to end the process which is running at the same time with an exit code in NodeJS. Syntax: process.exit( code ) Parameter: Â This function accepts single parameter as mentioned above and described below: Code: It can be either 0 or 1. 0 means end the process without a 2 min read Node.js process.send() Method The process.send() method is an inbuilt application programming interface of the process module which is used by the child process to communicate with the parent process. This method does not work for the root process because it does not have any parent process. Syntax: process.send(message, [sendHa 2 min read Node.js process.abort() Method The process.abort() property is an inbuilt application programming interface of the process module which is used to abort a running NodeJS process immediately. It also generates a core file. Syntax: process.abort() Parameter: This function does not accept any parameter. Return Type: It has a void re 2 min read Node process.cwd() Method The process.cwd() method is an inbuilt application programming interface of the process module which is used to get the current working directory of the node.js process. Syntax:process.cwd()Parameters: This method does not accept any parameters. Return Value: This method returns a string specifying 2 min read Node.js process.uptime() Method The process.uptime() method is an inbuilt application programming interface of the process module which is used to get the number of seconds the Node.js process is running. Syntax: process.uptime(); Parameters: This method does not accept any parameter. Return Value: It returns a floating-point numb 2 min read Node.js process.setuid() Method The process.setuid() method is an inbuilt application programming interface of the process module which is used to set the user identity of the Node.js process. Syntax:Â process.setuid(id) Parameters: This method accepts single parameter as mentioned above and described below:Â Â id: It is a required 2 min read Node.js process.getuid() Method The process.getuid() method is an inbuilt application programming interface of the process module which is used to get the numerical user identity of the Node.js process. Syntax: process.getuid() Parameters: This method does not accept any parameters. Return Value: This method returns an integer val 1 min read Node.js process.setgid() Method The process.setgid() method is an inbuilt application programming interface of the process module which is used to set the group identity of the Node.js process.Syntax:Â process.setgid(id) Parameters: This method accepts single parameter as mentioned above and described below:Â id: It is a required 2 min read Node.js process.getgid() Method The process.getgid() method is an inbuilt application programming interface of the process module which is used to get the numerical group identity of the Node.js process. Syntax: process.getgid() Parameters: This method does not accept any parameters. Return Value: It returns an object specifying t 1 min read Node.js process.seteuid() Method The process.seteuid() method is an inbuilt application programming interface of the process module which is used to set the effective user identity of the Node.js process. Syntax:Â process.seteuid( id ) Parameters: This method accepts single parameter as mentioned above and described below:Â Â id: It 2 min read Like