Hacker News new | ask | show | jobs
by bruce_one 2113 days ago
`readlink -e /proc/$$/exe` would be a simple solution on linux -> /proc is such a fun treasure trove of process info :-)

(Not sure it macOS has as much info in /proc?)

3 comments

> Not sure it macOS has as much info in /proc?

macOS does not have procfs

> macOS does not have procfs

https://en.wikipedia.org/wiki/Procfs

It also got dropped from OpenBSD:

> It was removed from OpenBSD in version 5.7, which was released in May 2015, because it "always suffered from race conditions and is now unused".[2]

The OpenBSD people don't say what you should replace it with, but backing up in the paragraph, the FreeBSD people do:

> As of February 2011, procfs is gradually becoming phased out in FreeBSD.[1]

Chasing that reference:

https://lists.freebsd.org/pipermail/freebsd-fs/2011-February...

> Why is procfs deprecated in favor of procstat?

[snip]

> The security issues are long-standing and there have been many over the years, but the real reason is something that's less evident (or at least less directly apparent):

> Simply put, procfs on FreeBSD has been neglected. There isn't a lot of attention being given to it, and the only modifications in recent months/years have been generally minor compared to the rest of the tree. You can review some of the commits yourself:

> http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/fs/procfs/

> Others like yourself have asked what the state of procfs is, going back as far as 2005. Be sure to read the reply as well:

> http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/20...

Here's the FreeBSD procstat manpage:

https://www.freebsd.org/cgi/man.cgi?procstat

Aside from bitrot, is there a reason to prefer procstat over procfs?

Do you have any resources about /proc you'd recommend?
`man proc' is quite good. https://man7.org/linux/man-pages/man5/proc.5.html

/proc is Linux specific, but it's extremely useful. A lot of tools are actually built on top of it, for example ps.

  ngarvey@cheapo:~$ strace ps aux |& grep cmdline | head
  openat(AT_FDCWD, "/proc/1/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/2/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/3/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/4/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/9/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/10/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/11/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/12/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/13/cmdline", O_RDONLY) = 6
  openat(AT_FDCWD, "/proc/14/cmdline", O_RDONLY) = 6
does not work in Fish Shell.

  fish: $$ is not the pid. In fish, please use $fish_pid.

  readlink -e /proc/$$/exe

                     ^