I have a python script which takes in processes in csv format and decides things based on what's running, it's name, and how much cpu time it's using. I would like to add processes that also use lots of memory to said script. The problem, however, is that the command that I have been using for csv like output does not seem to have a parameter to pretty print the RSS memory usage. I do have access to the VSZ value however... The command I have so far is:

ps -e -o "\"%p\",\"%r\",\"%U\",\"%z\",\"%C\",\"%c\",\"%a\""
"  PID"," PGID","USER    ","   VSZ","%CPU","COMMAND        ","COMMAND                    "
"22418","22418","root    ","  4956"," 0.0","my_proc","my_proc arg1 arg2"
"26175","26175","root    "," 14020"," 0.0","bash","-bash"

Before any one asks.. Yes I can get the vss value if I do not wish to have the value pretty printed. Example:

 ps -o "rss"

However, this doesn't get fed all nice and neatly into my script to stop stupid people from doing stupid stuff. I've tried every letter of the alphabet I know except for the Russian ones to see if one of the values matches the pretty print values of ps. But alas, It is not a single letter. I can't help but feel like there is a better way to output all of the data I want in the format I want.


Turns out I can use the -o parameter in kind of a more screwy way to get the result that I wanted to achieve. Not ideal, but it works.

ps  -o "\"%p\",\"%r\",\"%U\",\"" -o rss -o "\",\"%C\",\"%c\",\"%a\""

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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