4

I am developing a node application and there is an option to set the process title (process name). This only sets it in some tools (like ps and top), but not in htop or netstat.

I found this article that explained how most applications do it, but it doesn't change in netstat.

That lead me to wonder where those programs are getting the process name. Would they be getting it from /proc/##/cmdline? (## being the PID of the process)

I figure messing with things in /proc is a bad idea (and probably not possible), so if this is where those programs are getting it, is there a way to change it?

5

There is nothing wrong with reading things from /proc. In fact, that is where those tools get that information from. There are actually three files with the command name.

/proc/PID/cmdline
/proc/PID/stat
/proc/PID/status

I believe it is usually obtained from stat.

| improve this answer | |
  • But why do ps and top have the changed process name, whereas netstat doesn't? – beatgammit Jun 25 '11 at 7:27
  • Apparently a process can change it's name, which changes /proc/PID/cmdline, but the stat entry does not change. So it depends on which place the tool looks to get the name. netstat seems to use the stat entry. – Keith Jun 25 '11 at 8:03
  • Apparently node was changing the values in stat, status, and comm, but not cmdline. I guess programs like htop and netstat read from cmdline. Anyway, thanks for the info! – beatgammit Jun 25 '11 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.