0

I have a app that starts a number of nodeJs processes. The processes are not all running the same JS code, there are about three types of 'roles' for the processes. Currently if I run something like htop to have a look at CPU usage, I have no way of distinguishing between the different scripts being run (e.g. if one is using a lot of CPU I have no way of knowing which JS script the node process is running).

Could anyone suggest a method by which I could identify which JS script a particular node process is running? (preferably via the shell).

UpTheCreek
  • 1,628
  • 10
  • 32
  • 48

1 Answers1

1

If these processes are all the same script file or executable binary, there's no way to tell because that information is kept "inside" the program itself. You could possibly indirectly infer it by looking at the files the process has open (lsof) or the network connections it has open (netstat). Depending on what the script does, secondary information like that could provide clues.

On the other hand, if each script is actually a separate executable file on your system, then you can extract the information you need from /proc/[pid]/cwd, /proc/[pid]/cmdline, and/proc/[pid]/environ.

If all else fails, you could go the difficult route of using the Gnu debugger (gdb) on the running processes.

Michael Martinez
  • 2,645
  • 3
  • 24
  • 35
  • It's the same binary unfortunately, processing different scripts. The open files route is an option I hadn't considered, and might be doable. Thanks! – UpTheCreek Sep 16 '13 at 20:25