I'm trying to export the output of the "top" command (unix) with PHP. Invoking and reading the command/output is pretty simple using the "exex" function but the question is: is the "top" command output (order, names, etc.) always the same? Or is it related to the distribution I'm using?
Is there any way to parse these information "generally" on UNIX systems?
Thanks in advance
You could use ps instead, with arguments -A and -o like so:
which would give you the output exactly like you specified when you called the command:
Arguments:
All STANDARD FORMAT SPECIFIERS that you could use, you can find in the man page of ps, but I've copied them also here for convenience:
https://gist.github.com/ivankovacevic/9918272
As mentioned by Lucas,
ps
is probably printing what you would expect.If your Unix flavour is Linux, I think
pidstat
(from thesysstat
package) is better suited for your needs (not to mention, documented in a clearer way, in my opinion).