omkar p
omkar p

Reputation: 63

Get current assigned process id in node js

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.

Upvotes: 2

Views: 2557

Answers (3)

MrFrenzoid
MrFrenzoid

Reputation: 1336

Node has several global methods and attributes, one of them being process which holds the current node process info.

enter image description here

Upvotes: 1

Muhammed Rahif
Muhammed Rahif

Reputation: 668

built-in/core modules process does this :-

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

Upvotes: 0

sptm
sptm

Reputation: 319

Process PID can be accessed by process.pid.

Upvotes: 1

Related Questions