Ticket #461: lsfsor.py

File lsfsor.py, 641 bytes (added by PaulFertser, 3 years ago)

Now with the name of the program using resource

Line 
1#!/usr/bin/python
2
3import dbus
4
5bus = dbus.SystemBus()
6usage = dbus.Interface(bus.get_object("org.freesmartphone.ousaged",
7                "/org/freesmartphone/Usage"), "org.freesmartphone.Usage")
8dbusi = dbus.Interface(bus.get_object("org.freedesktop.DBus",
9                "/"), "org.freedesktop.DBus")
10
11print "%-16sPolicy\tState\tUsers" % "Name"
12for i in usage.ListResources():
13        print "%-16s%s\t%s\t" % ( i, usage.GetResourcePolicy(i), usage.GetResourceState(i) ),
14        for s in usage.GetResourceUsers(i):
15                pid = dbusi.GetConnectionUnixProcessID(s)
16                cmdline = open( "/proc/%s/cmdline" % pid, 'r' ).read().replace("\0", " ")
17                print "%s %s" % ( pid, cmdline ),
18        print
19