When I run top I see a screen similar to this,
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
654 root 20 0 25.5g 147780 70084 S 3.7 0.9 72:08.69 Xorg
1687 me 20 0 9165008 1.4g 268488 S 1.3 8.9 163:06.01 qutebrowser
316 root -51 0 0 0 0 S 0.7 0.0 1:09.86 irq/51-DELL095A:00
683 me 20 0 810360 58212 41792 S 0.7 0.4 12:35.61 picom
702 me 20 0 246876 18032 14616 S 0.7 0.1 26:04.86 i3bar
827 me 20 0 665528 16316 9980 S 0.7 0.1 32:41.79 conky
2874827 me 20 0 6008688 209960 123060 S 0.7 1.3 0:10.84 QtWebEngineProc
675 me 20 0 175796 24656 15216 S 0.3 0.2 0:14.27 i3
771 me 9 -11 1022184 21952 12056 S 0.3 0.1 82:23.43 pulseaudio
but the program is interactive, so I see the screen changing as time passes (which is ok because the info does change over time). Furthermore, top | grep whatever doesn't seem to return ever.
What if I want a snapshot of that state for sending it to a text processing utility?
A comment suggested to go for top -b -n 1, but if I pipe that into some other program (or, for simplicity, if I > some-file), I see that it also has kind of heading,
top - 21:35:47 up 5 days, 7:24, 1 user, load average: 0.16, 0.41, 0.37
Tasks: 243 total, 1 running, 241 sleeping, 1 stopped, 0 zombie
%Cpu(s): 2.3 us, 3.1 sy, 0.0 ni, 93.8 id, 0.0 wa, 0.0 hi, 0.8 si, 0.0 st
MiB Mem : 15787.2 total, 1840.9 free, 5693.1 used, 8253.3 buff/cache
MiB Swap: 16384.0 total, 16375.2 free, 8.8 used. 6256.7 avail Mem
It would be nice to have a clean tabular report of all processes running, and nothing more.
Should I use an utility other than top?
Is maybe ps -e what I should reach for?
The scenario in which I plan to use this solution is for a PID picker for a debugger: the user would write the name of the process, and the PID picker would filter the list of running processes based on that; then when the user selects the desired process, the corresponding PID is used to attach the debugger.
top -b -n 1 -u paul > fooruns in batch mode, runs one cycle, and writes a snapshot to the redirection (file or pipe). The Big Deal is that it omits all the ncurses terminal controls in -b mode.top. Maybe ask that question separately with tags for whichever platform you're on and shell you're running?