0

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

2
  • Please tag your question with OS distro. ps has some very different option sets between BSD, UNIX, and Linux. Commented Jun 16 at 19:12
  • Hm.. the script will be used at Ubuntu, CentOS, AlmaLinux etc. Will Linux be enough?
    – palmasd1
    Commented Jun 17 at 4:22

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .