Finding processes using ALSA sound fast Finding processes using ALSA sound fast linux linux

Finding processes using ALSA sound fast


There is an answer for this question on the ALSA FAQ. On my system, using fuser is way faster than using lsof.

fuser -v /dev/snd/*


You start a lot of processes here. Instead you can try doing in a similar way to the lsof script you posted... but replacing lsof by a shell for loop:

If you want to avoid launching lots of grep processes, start only one:

#!/bin/shfor i in /proc/[0-9]*/fd/*do    echo ${i%/fd/*} $(readlink $i)done | grep -q /dev/snd/pcm

This takes now 4.5s on my desktop, compared to 7.5s when there's one grep process for each opened file.

But... your grep is not necessary here, I think. If you care so much, you can try:

#!/bin/shfor i in /proc/[0-9]*/fd/*do    var="$(readlink $i)"    if test x"$var" != x"${var#/dev/snd/pcm}"    then        echo $i    fidone

This is even faster for me (test is almost always a shell builtin), but I guess this is more because of bad testing methods. Try yourself.


You don't say what kind of timescales you're looking for but for your alternative suggestion

for i in /proc/[0-9]*/fd/*;

might work and give you a bit of speed up, as might using cut rather than awk.