ps axo : display full username based on PID number

https://stackoverflow.com/questions/74259929/ps-axo-display-full-username-based-on-pid-number

Asked 3 years, 2 months ago Modified 3 years, 2 months ago Viewed 722 times 1

I am trying to display full username by PID number

The first Approach i tried :

PID=12345 PID_USER=ps -u -p ${PID}| awk '{print $1}' | tail -1 echo $PID_USER this will display as systemU+, i want to display as SystemUser_Farid

i have tried a second approach using ps axo , script used as

ps axo user:20,pid , however , this is printing the whole list of processes , using ps axo -p ${PID} user:20,pid doesnt show any result.

linuxbashshell Share Improve this question Follow asked Oct 31, 2022 at 7:23 Farid Arshad’s user avatar Farid Arshad 33255 silver badges2222 bronze badges 2 ps -o user= -p $PID works fine here – oguz ismail CommentedOct 31, 2022 at 7:26 I was searching for hours. Thanks!!!!!!! – Farid Arshad CommentedOct 31, 2022 at 7:35 Add a comment 1 Answer Sorted by:

Highest score (default) 3

Use -o format for a user-defined format and only print the user name:

ps -o user= -p “$PID” The = disables printing the header line.

Share Improve this answer Follow answered Oct 31, 2022 at 9:17 knittl’s user avatar knittl 270k5959 gold badges339339 silver badges405

Updated: