Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "$1" = '-h' -o "$1" = '--help' ]; then
- me="${0##*/}"
- echo "$me: list ALSA devices and relevant information."
- exit 0
- fi
- for (( i=0; i<10; i++ )); do
- if [ -d "/proc/asound/card${i}" ]; then
- cname="$( grep -E "^ ${i} " '/proc/asound/cards' 2>/dev/null | cut -d '[' -f 2 | cut -d ']' -f 1 | sed -e 's@ *$@@' )"
- echo "Card ${i} (${cname}):"
- for t in 'p' 'c'; do
- case "$t" in
- p) typeString='Playback' ;;
- c) typeString='Recording' ;;
- esac
- for (( j=0; j<10; j++ )); do
- if [ -d "/proc/asound/card${i}/pcm${j}${t}" ]; then
- dname=''
- if [ -e "/proc/asound/card${i}/pcm${j}${t}/info" ]; then
- dname="$( grep -E '^name: ' "/proc/asound/card${i}/pcm${j}${t}/info" 2>/dev/null | cut -d ' ' -f 2- )"
- fi
- echo
- if [ -n "$dname" ]; then
- echo " * ${typeString} Device ${j} (${dname}):"
- else
- echo " * ${typeString} Device ${j}:"
- fi
- ownerPID="$( grep -E '^owner_pid' "/proc/asound/card${i}/pcm${j}${t}/sub0/status" 2>/dev/null | tr -cd '0-9' )"
- if [ -n "$ownerPID" ]; then
- ownerName=''
- if [ -e "/proc/${ownerPID}/comm" ]; then
- ownerName="$( cat "/proc/${ownerPID}/comm" 2>/dev/null )"
- fi
- if [ -n "$ownerName" ]; then
- echo " used by: ${ownerName} (PID ${ownerPID})"
- else
- echo " used by: some program (PID ${ownerPID})"
- fi
- fi
- while read line; do
- echo " $line"
- done < "/proc/asound/card${i}/pcm${j}${t}/sub0/hw_params"
- fi
- done
- done
- echo
- fi
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement