Skip to main content
2 of 2
replaced http://superuser.com/ with https://superuser.com/

First of all, ps aux | grep <PID> is useful when you want to show the details for a specific process whose PID (Process Identifier) is represented by <PID>.

For example (ps aux | grep 'firefox\|USER' means print only lines that contein firefoxor USER):

ps aux | grep 'firefox\|USER'
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
terdon  9021  2.5 11.8 1950888 970832 ?      Sl   Apr03 108:41 /opt/firefox/firefox

So, the PID for my firefoxinstance is 9021. So, to use the command you are trying to run, I would replace <PID> with 9021:

ps aux | grep 9021
terdon  9021  2.5 11.5 1948776 942640 ?      Sl   Apr03 109:03 /opt/firefox/firefox

Now, I am not sure what you mean by "display which files running these processes". If you mean display which files these processes are using, ps aux is one way of doing so. Say I have opened the file /usr/share/doc/nano/faq.html using this command:

 firefox /usr/share/doc/nano/faq.html 

I could see which file firefox had opened using ps :

ps aux | grep firefox
terdon   31763 18.7  1.0 682916 84352 pts/10   Sl+  17:10   0:02 firefox /usr/share/doc/nano/faq.html

The opened file is shown as one of the arguments passed to firefox. Note that the PID is different (it is now 31763 instead of 9021) that is because every running program has its own unique PID.


Another useful command is top. If you run it with the -c switch it will show the arguments passed to a command, and with -u <your user> it will only show processes started by your user name (replace <your user> with your actual user name):

top -c -u terdon

This is the output on my local machine (user terdon is only running two processes):

top - 17:14:41 up 3 days, 49 min, 14 users,  load average: 0.48, 0.54, 0.55
Tasks: 228 total,   1 running, 226 sleeping,   0 stopped,   1 zombie
%Cpu(s):  7.1 us,  5.5 sy,  0.0 ni, 86.5 id,  0.0 wa,  0.0 hi,  0.9 si,  0.0 st
KiB Mem:   8187940 total,  8007220 used,   180720 free,   349264 buffers
KiB Swap:  8191996 total,     5556 used,  8186440 free,  4173004 cached

  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                                       
31573 terdon    20   0 24900 5576 1684 S   0.0  0.1   0:00.20 bash                                                          
31763 terdon    20   0  666m  77m  28m S   0.0  1.0   0:02.39 firefox /usr/share/doc/nano/faq.html                          

For an explanation of the information shown by top, see my answer to a related question on SU.

terdon
  • 252.2k
  • 69
  • 480
  • 718