Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to grab process information about processes that are using over a certain CPU limit.


#!/usr/bin/env python

def get_processes_over_usage(cpu_usage):

    #Find the processes.

    return processes

Specifically, I'm looking for the executable and the username of the process.


Here is the answer, I just can't post it yet: This doesn't exactly conform to the requirements, but it's close enough.

#!/usr/bin/env python

import commands

def get_processes():

    output = commands.getoutput('/usr/bin/top  -n 1')

    lines = output.split('\n')

    header = ['PID', 'USER', 'PR', 'NI', 'VIRT', 'RES', 'SHR', 'S', '%CPU', '%MEM', 'TIME+', 'COMMAND']

    header_found = False
    processes = []

    for line in lines:  
        data = line.split()

            processes.append(dict(zip(header, data)))

        if(data == header):
            header_found = True

    return processes
share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.