After much searching and sending email to the maintainer (Vojtech Pavlik), a solution was found!
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <stdio.h>
#define ERROR (-1)
main() {
int fd=open("/dev/tty0",O_RDWR|O_NDELAY);
if (fd<0) {
perror("/dev/tty0");
exit(2);
}
/* 125 = 125 milliseconds, or 1/8th of a second;
0x637 is the number of clock cycles in the standard kernel beep */
if (ioctl(fd,KDMKTONE,(125<<16)+0x637) == ERROR) {
perror("/dev/tty0: ioctl");
exit(2);
}
close(fd);
}
Initially this was tried with /dev/tty and /dev/console, and it didn't work with either of them. Only /dev/tty0 worked, and even that would not have worked if CONFIG_VT was disabled in the kernel configuration.
Many thanks to Vojtech!