HOWTO: Make Your Linux System Beep

| No TrackBacks
Have you ever wanted a way to make your system audibly alert you when something [interesting,good,bad] happens?  Using a very simple C-program, you can.  I've configured my Linux box to beep when users login, and when the system restarts.  With a little work, you can also configure a Bash script to call beep if Apache encounters a 403 Forbidden error.  I use this a lot when running a long build; I'll start the build such that it will "beep" when it's done, I'll go do something else, and wait for the audible alert before I return to my system.  Multitasking at its finest.  Continue reading for the code.
Here's the C code.  Note you need to be root to run it, or configure sudoers accordingly.

#include <stdlib.h>
#include <fcntl.h>
#include <linux/kd.h>

int main(int argc, char *argv[]) {
int fd = open("/dev/tty10", O_RDONLY);
if (fd == -1 || argc != 3) return -1;
return ioctl(fd, KDMKTONE, (atoi(argv[2])<<16)+(1193180/atoi(argv[1])));
}

To compile, run:

#/>  gcc -o beep beep.c

As root, run:

(root)#/>  ./beep Hz Duration

First argument is frequency of the beep in Hz.  The second is the duration of the beep in milliseconds.  Some of my favorites include ...

When something bad happens, a low and short 100 ms flurp:

(root)#/>  ./beep 300 100

When someone logs in:

(root)#/>  ./beep 1000 200

If you want to see how to do this in x86 assembly, perhaps you would find this interesting.

Enjoy.

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

No TrackBacks

No trackbacks attached to this entry.

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on November 3, 2008 12:40 PM.

Happy Halloween and a Spooky Ghost from the jQuery Pumpkin was the previous entry in this blog.

Apple iPhone System Sounds (CAF to MP3) is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.