All pastes #62953 Raw Edit

Unnamed

public text v1 · immutable
#62953 ·published 2006-06-07 14:34 UTC
rendered paste body
#!/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():
                        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()