Python System Information
6cb503998002 — default tip 3 years ago
Added tag 0.3b3 for changeset 3ba75cf135b7
3ba75cf135b7 — 0.3b3 3 years ago
Change source code location
Ignore EIO, ENOENT and ENOTDIR when checking cwd


PSI - Python System Information

PSI is a Python package providing real-time access to processes and
other miscellaneous system information such as architecture, boottime
and filesystems. It has a pythonic API which is consistent accross all
supported platforms but also exposes platform-specific details where


You need to check if it's supported on your platform, check the
docstring of for the exact supported platforms.

You will also need a working C compiler and the python development
files.  If a system is not supported yet the build will fail.  After
building it is best to run the test suite, on some platforms not all
tests might pass yet and you would rather know of these problems
before starting to use PSI.

So to fully install PSI from source::

  $ python build
  $ python test
  $ python install [<your options>]

See the Python documentation on installing Python module for more

Here a rough list of packages you will need for some popular GNU/Linux
distributions, this should give you an idea of what is needed.


 - python
 - python-dev
 - gcc


 - python
 - python-devel
 - gcc



The argv array is read from the process memory on Solaris.  If you do
not have permissions to do this only the ``command`` and ``argc``
attributes of ``psi.process.Process`` will be available and using the
``args`` attribute will return the appropriate ``AttributeError``.

Unit Tests

To run the unit tests::

  $ python test

Some tests require superuser privileges and will be silently skipped
when not running as root.  This is required to run test applications
with specific schedulers and priorities.

If any tests fail, please copy & paste the output and send operating
system version, python version, python executable format (32/64-bit)
and any other applicable details to the mailing list


Examples are the best documentation.  :-)


  Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
  [GCC 4.3.2] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import psi, psi.arch, psi.process
  >>> a = psi.arch.arch_type()
  >>> a
  >>> isinstance(a, psi.arch.ArchLinux)
  >>> isinstance(a, psi.arch.ArchSunOS)
  >>> a.sysname
  >>> a.nodename
  >>> a.release
  >>> a.release_info
  (2L, 6L, 26L)
  >>> a.version
  '#1 SMP Thu Nov 20 21:57:00 UTC 2008'
  >>> a.machine
  >>> psi.loadavg()
  (0.059999999999999998, 0.13, 0.13)
  >>> import os
  >>> mypid = os.getpid()
  >>> mypid
  >>> p = psi.process.Process(mypid)
  >>> p.args
  >>> p.exe
  >>> p.uid
  >>> import pwd
  >>> pwd.getpwuid(p.uid)
  pwd.struct_passwd(pw_name='flub', pw_passwd='x', pw_uid=1000,
  pw_gid=1000, pw_gecos='Floris Bruynooghe,,,', pw_dir='/home/flub',
  >>> p.start_time
  datetime.datetime(2009, 5, 11, 20, 4, 31, 709993)
  >>> help(psi.process.Process.start_time)
  Help on getset descriptor psi.process.Process.start_time:

    Start time of process as datetime.datetime object

    Use .strftime('%s') to get seconds since epoch
  >>> p.ppid
  >>> parent = psi.process.Process(pid=p.ppid)
  >>> parent.args
  >>> p.rss
  >>> pt = psi.process.ProcessTable()
  >>> len(pt)
  >>> pt.keys()
  [1L, 2L, 3L, 4L, 5L, 6L, 7L, 6152L, 5660L, 6687L, 4648L, 5674L,
  5639L, 6834L, 46L, 48L, 50L, 51L, 5684L, 1081L, 2621L, 5184L, 6276L,
  2627L, 6217L, 6220L, 6221L, 4877L, 6224L, 6227L, 6229L, 6235L,
  6757L, 5729L, 6244L, 2149L, 6246L, 2152L, 2153L, 6763L, 6764L,
  6254L, 6248L, 6259L, 5749L, 2166L, 6249L, 2169L, 5242L, 2683L,
  6781L, 6273L, 6274L, 4740L, 6278L, 6279L, 5772L, 5776L, 6290L,
  5779L, 5268L, 6296L, 6809L, 156L, 157L, 158L, 6341L, 6307L, 2212L,
  6257L, 20654L, 6856L, 4786L, 4788L, 5814L, 5817L, 6263L, 5821L,
  6261L, 6336L, 4811L, 118L, 200L, 1739L, 5837L, 1742L, 1743L, 6349L,
  20693L, 6265L, 5852L, 122L, 4833L, 4834L, 1253L, 2793L, 1258L,
  6382L, 21374L, 6393L, 5885L, 1278L, 5376L, 6401L, 5675L, 1290L,
  1293L, 6445L, 5397L, 6262L, 5913L, 4385L, 4386L, 4392L, 4393L,
  4394L, 1074L, 6449L, 5426L, 6456L, 6458L, 5951L, 19779L, 5963L,
  5964L, 21327L, 21304L, 5466L, 4955L, 4444L, 2404L, 5501L, 6526L,
  4992L, 4993L, 6032L, 6572L, 6442L, 5573L, 5576L, 2794L, 17357L,
  4054L, 6397L, 6136L]
  >>> q = pt[6856]
  >>> q.args
  >>> q.env
  {'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'LOGNAME':
  'flub', 'USER': 'flub', 'HOME': '/home/flub', 'PATH':
  'DISPLAY': ':0.0', 'SSH_AGENT_PID': '6217', 'LANG': 'en_GB.UTF-8',
  'SHELL': '/bin/bash', 'XDG_SESSION_COOKIE':
  'SESSION_MANAGER': 'local/signy:/tmp/.ICE-unix/6152',
  'XDG_DATA_DIRS': '/usr/local/share/:/usr/share/:/usr/share/gdm/',
  '/tmp/seahorse-SWS6qW/S.gpg-agent:6235:1', 'USERNAME': 'flub',
  '/tmp/keyring-AStyaD/ssh', 'DESKTOP_SESSION': 'gnome', 'GDMSESSION':
  'ORBIT_SOCKETDIR': '/tmp/orbit-flub', 'XAUTHORITY':
  '/home/flub/.Xauthority', 'GNOME_KEYRING_SOCKET':
  '/tmp/keyring-AStyaD/socket', 'GNOME_KEYRING_PID': '6246\n',
  'GDM_LANG': 'en_GB.UTF-8', 'PWD': '/home/flub', 'GTK_RC_FILES':
  >>> r = []
  >>> for pp in pt.values():
  ...     if pp.args and 'evolution' in pp.args[0]:
  ...         r.append(pp)
  >>> r
  [psi.process.Process(pid=6336), psi.process.Process(pid=6572),
  >>> for pp in r:
  ...     print ' '.join(pp.args)
  /usr/lib/evolution/2.24/evolution-exchange-storage --oaf-activate-iid=OAFIID:GNOME_Evolution_Exchange_Connector_CalFactory:1.2 --oaf-ior-fd=22
  /usr/lib/evolution/evolution-data-server-2.24 --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2 --oaf-ior-fd=23
  >>> init = psi.process.Process(1)
  >>> init.env
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  psi.InsufficientPrivsError: Insufficient privileges for Process.env

Some sample scripts are also available in the examples/ subdirectory.


You should definitely read the DESIGN file, it will explain the ideas
behind how the code is structured and how you should extend it.  Also
very useful is the TODO file and the wiki

The has some extra features that help with development,
these are explained in its docstring.

The PSI source code is hosted at bitbucket in a Mercurial repository,


If PSI does not yet work on your architecture/system then it needs to
be ported, the design is aimed at making this easy for you.  There is
no separate porting guide at the moment so you will have to read the
DESIGN file for details of what to do.


There is a mailing list at where you can
post questions, patches, hints, bugs, etc.  Your feedback is welcome!