1

I'm using windows, and I'm doing this experiment,

console.log( _.process.exec( "mongod --dbpath . --port 8083 --bind_ip 127.0.0.1" ).pid );

The problem is, when I do a tasklist command, the PID from that output points to the command prompt task and not to the mongod.exe task.

Is there a way to get the real PID of the mongod.exe task?

Richeve Bebedor
  • 2,138
  • 4
  • 26
  • 40

2 Answers2

1

That's because mongod is a child process of cmd and tasklist doesn't print child process ids.

Given a parent process id, you can get a list of it's children with a wmi query:

wmic process where (ParentProcessId=CMD_PID) get Caption, ProcessId

Replace CMD_PID with the parent(cmd) process id.

Community
  • 1
  • 1
fardjad
  • 20,031
  • 6
  • 53
  • 68
  • I see the child process via tasklist.exe. Not sure how to grab that and use it within the Node app though. I need to kill it by PID later. – Naikrovek Mar 21 '13 at 16:50
1

I'm looking at this now and thinking that I'll need to run process.pid in the child and signal it back to the parent. The parent then needs to keep track of the number in case the child needs to be killed.

I was hoping this wouldn't be so complicated?

Bob Brunius
  • 1,344
  • 5
  • 14
  • 21