Linux – Where does netstat get the process name

linuxnetstatprocess

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?

Best Answer

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.