I want to get current process id which is currently used.I'm using cluster for multiprocessing. I need this because I want to kill child process after the use to reduce memory utilise but I only get the current process Id when I call process.exit()
method. But I don't want to call process.exit()
method in each route and cluster.on('exit')
couldn't called.
Process PID can be accessed by process.pid
.
const process = require('process'); // On ubuntu, you dont need this (if there is an error)
if (process.pid) {
console.log('This process is your pid ' + process.pid);
}
Another answer from stackoverflow:- NODEJS process info
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.