Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Which files does the linux command "top" read from in order to build its table of data? Specifically, I'd like to be able to find the data for the "command" column based off of a PID.

share|improve this question
    
What sort of data are you looking for? Full path and arguments? other? –  Doug Harris Sep 17 '09 at 20:10

3 Answers 3

up vote 9 down vote accepted

It's in /proc/$pid/cmdline. The fields are nul separated. Example on my machine:

$ xargs -0 echo < /proc/4263/cmdline 
/usr/lib64/firefox-3.5.3/firefox -no-remote -P default
$
share|improve this answer

top gets its information from the files found in procfs aka /proc

you can query based off the pid by using

ps

unfortunately i don't recall the syntax of the command...

share|improve this answer
1  
"man ps" or "ps --help" –  Doug Harris Sep 17 '09 at 20:08

You can use ps to get the name of the command link to a particular PID

ps [PID]

It will also give you additional information based on the parameters you pass. See here for more details.

Alternatively you can download the top source code which should give you a more precise answer to the question.

Also this PerlMonks article explains how to simulate top on a AIX system, which also makes use of the ps command.

share|improve this answer
1  
The example code shows PS (upper-case). Linux newbies beware, that won't work -- use "ps" (lower-case). The rest of you already knew that. –  Doug Harris Sep 17 '09 at 20:13
    
@Doug - Fixed. Oversight on my side. Thanks for clarifying. –  Diago Sep 18 '09 at 5:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.