Restarting the Linux sound subsystem

Sometimes my laptop gets to a state in which sound works through the built-in speakers, but not through the headphone jack. Possibly my solution is too brutal, but it works -  restarting the whole sound subsystem. I guess that it may come handy in other situation: the ability to restart a subsystem instead of rebooting the machine, is always an advantage.

The rationale is simply reloading the kernel module that acts as a driver to our sound hardware. Reloading isn't easy, as:

  1. Kernel modules use this module.
  2. User processes use this module.

So the solution is to first kill all processes which use the sound (on a healthy system nowadays it's only pulseaudio), recursively unload sound driver and the modules that depend on it, then reload the main kernel module. On my system, with Intel sound card, the sound driver's module name is snd_hda_intel.

Therefore here is the full, 3-step process:

[cc lang="bash"]$ killall pulseaudio; sleep 3; killall -9 pulseaudio[/cc]

Note: you'll need sudo if there are pulseaudio processes running as other users.

[cc lang="bash"]$ sudo modprobe -r snd_hda_intel[/cc]

Note: make sure modprobe didn't throw an error. If it did, there's probably still a process using the kernel module. Sometimes that's because a new pulseaudio process got created.

[cc lang="bash"]$ sudo modprobe snd_hda_intel[/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *