Beep on Linux in C

倾然丶 夕夏残阳落幕 提交于 2019-11-27 04:51:28

Please look at the standard linux beep source code. http://www.johnath.com/beep/beep.c

It uses KIOCSOUND ioctl to "beep", but you don't need superuser privileges to make it play. I have configured it to be readable and executable by users on the "beep" group.

So my standard user with UID 1000 is in the group with GID 501 (i called it "beep"). Next to this I had to chmod 4750 /usr/bin/beep and now I'm able to play beeps (in the range 20-20000Hz) without asking for superuser privileges.

I think the only way to do this is to either use suid to give my own program root access, or to use beep, which already has suid. I suppose I will just add one more dependency, then, as beep is not too big anyway.

Thank you for all the answers, I'm sure other libraries are great for more complex signals, but I need a very simple one!

I think this question can be marked as solved / closed, then.

If anybody finds a way to create a beep using the console without superuser-privileges, I'm still interested in this solution :)

Thank you all again.

The most basic beep is still '\a' , if your terminal supports it:

fprintf(stdout, "\aBeep!\n" );

Try using an audio library such as OpenAL.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!