Get the username and the process ID of a process in bash
You can parse out the /proc
entry if you are on Linux and if you just need a numeric pid (or are OK with it). Here is an example for the mysqld
process:
grep -e '^Uid:' /proc/$(pidof mysqld)/status | cut -f 2
This can happen if the username is longer than 8 characters (OR) id has no name. But, If you want the username in the ps
output then try this,
ps -eo uname:20,pid,pcpu,pmem,sz,tty,stat,time,cmd | grep '[b]ash'