#!/usr/bin/python # 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(): for pid in line.split(): if pid != "": tmp.append(pid) # convert pids to application names for pid in tmp: f = os.popen("ps " + pid, "r") for line in f.readlines(): items = line.split() 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()