All pastes #62951 Raw Edit

Something

public text v1 · immutable
#62951 ·published 2006-06-07 14:28 UTC
rendered paste body
# Working program:
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()