Search code examples
linuxshellcommandps

How to get all process ids without ps command on Linux


How to get all process ids (pid) (similar to: $ ps aux) but without using ps.

One example of when this would be used is when developing a dotnet 5 application to run on a docker host. The dotnet runtime image is a very cut-down Linux image, with bash, but without ps. When diagnosing an issue with the application, it's sometimes useful to see what processes are running and if separate processes have been spawned correctly. ps is unavailable on this image. Is there an alternative?


Solution

  • On Linux, all running process have "metadata" stored in the /proc filesystem.

    All running process ids:

    shopt -s extglob # assuming bash
    (cd /proc && echo +([0-9]))