#!/usr/bin/python # -*- coding: utf-8 -*- # Working program: import os class tools: def alsaUsedBy(self): result = [] tmp = [] f = os.popen("fuser /dev/snd/* /dev/dsp* /dev/snd/*", "r") # get pids: for line in f.readlines(): print "LINE", line for pid in line.split(): print "PID", pid if pid != "": tmp.append(pid) print "Half way done", tmp # convert pids to application names for pid in tmp: print "PID2", pid f = os.popen("ps " + pid, "r") for line in f.readlines(): print "PSLINE", line items = line.split() print "ITEMS", items if items[0] != "PID" and len(items) >= 5: if items[4] not in result: result.append(items[4]) return result if __name__=="__main__": h = tools() print "Sound is used by the following applications:" print h.alsaUsedBy()