How to get process username using PID on Mac OS?

I used getpid()to find out the PID of the process, and now, how can I get the username of the process?

I tried this shell command ps -o user= PIDNUM, but on Mac 10.4 this does not work for me.

Are there any other methods?

+5
source share
3 answers

I would use and : ps awk

% ps aux | awk -v PID=13521 '$2 == PID { print $1 }'
root

... where 13521is the PID in question. Replace your own PID or ${environment_variable}to your liking!

If you do not have a PID, you can find all users running Google Chrome (for example):

% ps aux | awk -v app='Google Chrome' '$0 ~ app { print $1 }'  
+4
source

ps -ef | grep <process_pid> --- This will give you all the necessary information.

+1
source

following: ps -efj | grep PID

Where

  • e: select all processes
  • f: full format list
  • j: job management format.

[ http://linux.die.net/man/1/psău[1]

+1
source

All Articles