6

How can I trace which program is making the computer beep periodically?

Is beeping usually done by writing something to /dev/tty*? How can I monitor which programs are writing to /dev/tty*?

The beep is not at the same frequency as when I do printf '\a' > /dev/tty1.

It vanishes on rmmod pcspkr and reappears on modprobe pcspkr.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
Vi.
  • 17,755

2 Answers2

4

On Linux and most UNIX based OSes, just printing the BELL character (Ctrl+G or '\a') will trigger a beep.

This is implemented through an ioctl() syscall, which is in your shell (bash, etc. support this). The syscall then goes through the kernel and is finally implemented by the pcspkr device, a kernel module. You can see pcspkr loaded with lsmod and unload it with modprobe -r or rmmod.

Don't even think about /dev/tty when thinking about beeps, because even headless programs that aren't bound to a TTY can produce a beep. Run strace -eioctl bash and in the bash prompt run echo ^a. You'll see that producing a beep is a simple but fairly specific ioctl() call (#include <sys/ioctl.h> and <linux/kd.h> if writing a C/C++ program to do this.)

References:

  1. http://tldp.org/LDP/lpg/node83.html
  2. http://www.linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux
allquixotic
  • 34,882
1

Using this script (try with caution)

function ppid() { cat /proc/"$1"/status | grep PPid: | grep -o "[0-9]*"; };
function pidtree() { P=$1; while [ "$P" != "1" ]; do echo $P; P=`ppid $P`; done; echo 1; };
strace -fe execve `( pgrep ''; pidtree $$ ) | sort | uniq -u | sed 's/^/-p /'`

I found out that ImageMagick's "import" is periodically taking screenshots and causing beeps. Added -silent — now beeps gone.

Vi.
  • 17,755