I want to get info about running processes and pass output to script.
I have line shows the running MariaDB
instance but its user is mysql
.
Is there a way to get all of ps waxfu
output excluding username?
mysql ... /usr/sbin/mariadbd
-> ... /usr/sbin/mariadbd
1 Answer
On a Linux box, you are likely have ps from procps with tons of features and modes. I assume procps, if something else read its manual.
u
option is a "user-oriented format" which does display user. If you don't want user, omit this option.
f
"forest" option makes a process tree in the output. This will be unreadable when sorting or parsing output, omit this.
When scripting, be specific in the output format with named fields, so it will not change on you. For a default set of fields minus user this might be useful:
ps wwax o pid,%cpu,%mem,vsz,rss,tty,stat,start,time,command
Output columns are delimited by many spaces. Although command
may contain spaces. Parsing this into rows and columns might require something a little fancy, like awk.
ax
is all processes, removing both the "only yourself" and "must have a tty" restrictions. Useful to a human operator to show everything. However sometimes in a script limited to a smaller subset, you may wish to filter processes by command name or group.
In a script, there may be easier programmatic methods to get data on all processes. Check if your language has an existing library to iterate over processes.
Linux
be enough?