Home > python > psutil: a cross-platform process and system utilities module

psutil: a cross-platform process and system utilities module

psutil is a module providing an interface for retrieving information on all running processes and system utilization (CPU, disk, memory) in a portable way by using Python, implementing many functionalities offered by command line tools such as: ps, top, df, kill, free, lsof, netstat, ifconfig, nice, ionice, iostat, iotop, uptime, tty. It currently supports Linux, Windows, OSX and FreeBSD both 32-bit and 64-bit with Python versions from 2.4 to 3.3 by using a single code base.” (source)

Example
Let’s kill a process by name:

# http://stackoverflow.com/questions/2940858/kill-process-by-name-in-python
import psutil

PROCNAME = 'chromedriver'

def kill_chromedriver():
    for proc in psutil.process_iter():
        if proc.name == PROCNAME:
            proc.kill()
Categories: python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: