Finding PID Everywhere


the proc virtual filesystem

Usually at least one of those is present on any system

  • top
  • htop / another top variant
  • ps

But sometimes the usual suspects are not available, especially in minimal containers.

But there is another, more low level, way that works: /proc

This is a virtual filesystem provided by the kernel about running processes.

So to mirror something like this:

$ ps aux |grep sleep
    5 root      0:00 sleep 1000
   21 root      0:00 sleep 10000000
   36 root      0:00 grep sleep

We could do:

$ grep sleep /proc/*/cmdline
/proc/21/cmdline:sleep
/proc/5/cmdline:sleep
/proc/self/cmdline:sleep
/proc/thread-self/cmdline:sleep

The /proc file system is a pretty interesting thing to check out beyond this use as well!

  • There is exe, which links to the executed binary
  • Or environ, which contains all environment variables of the process

GeeksForGeeks has a good overview available.

See also