Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all process ids without ps command on Linux

Tags:

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?

like image 572
WB Lee Avatar asked Oct 02 '15 18:10

WB Lee


People also ask

How do I find the process ID of a process in Linux?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

How do I list all processes in Linux?

To list currently running processes, use the ps , top , htop , and atop Linux commands. You can also combine the ps command with the pgrep command to identify individual processes.

How do I find PID of all processes?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort.


2 Answers

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])) 
like image 138
glenn jackman Avatar answered Sep 19 '22 11:09

glenn jackman


Further to the comment by @FelixJongleur42, the command

ls -l /proc/*/exe 

yields a parseable output with additional info such as the process user, start time and command.

like image 33
spume Avatar answered Sep 17 '22 11:09

spume