"arecord: ... audio open error: Device or resource busy"

From Noah.org
Jump to: navigation, search


When trying to record some sound from the command-line you see an error message like this:

# arecord -d 5 -f S16_LE -r 44100 -D plughw:2,0 test.wav
arecord: main:828: audio open error: Device or resource busy

This puzzled me for a while because I couldn't see anything obvious running on my laptop. I figured some kernel thing had left something lying around. But I didn't see any defunct zombie processes running. So the process was still running or the kernel itself had the sound hardware reserved. I used fuser to see what was using anything under /dev/snd/*.

# fuser -fv /dev/snd/*
                     USER        PID ACCESS COMMAND
/dev/snd/controlC0:  root        843 F.... pulseaudio
/dev/snd/controlC1:  root        843 F.... pulseaudio
/dev/snd/controlC2:  root        843 F.... pulseaudio
/dev/snd/pcmC0D0p:   root        843 F...m pulseaudio
/dev/snd/pcmC1D0c:   root        843 F...m pulseaudio
/dev/snd/pcmC2D0c:   root        843 F...m pulseaudio
/dev/snd/pcmC2D0p:   root        843 F...m pulseaudio

I don't know how pulseaudio got started and I don't know how I did not notice it running. Fortunately that what fuser was made for. The fact that all the pcm devices were mmap'ed is what was locking the audio device.