Page 1 of 5 123 ... LastLast
Results 1 to 10 of 45

Thread: How to make your computer beep

  1. #1
    Join Date
    Aug 2011
    Location
    usa
    Posts
    232

    Default How to make your computer beep

    A few days ago I decided it would be fun to make my computers internal speaker beep. So I wrote a short C program.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("\a\n");
        return(0);
    }
    It did not beep.
    A few days later I was going through interesting man pages and came upon busy box.
    It also had a beep program so I used it.

    Code:
    $busybox beep
    beep: can't open console
    It did not beep.
    So I used:

    Code:
    $sudo busybox beep
    And it worked. So, what's up?
    Why do I need superuser privileges?
    If I want a program that I make to beep how do I do it without superuser privileges?

  2. #2
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make your computer beep

    On 2014-01-11 21:06, ballsystemlord wrote:
    >
    > A few days ago I decided it would be fun to make my computers internal
    > speaker beep.


    Yes, it would.
    I tried this many years ago...

    Code:
    Telcontar:~ # l /root/bin/beep
    -rwxr-xr-- 1 root root 686 Apr  6  2002 /root/bin/beep*
    Telcontar:~ #

    > So I wrote a short C program.
    >


    > It did not beep.


    I know...

    > A few days later I was going through interesting man pages and came upon
    > busy box.
    > It also had a beep program so I used it.
    >
    >
    > Code:
    > --------------------
    >
    > $busybox beep
    > beep: can't open console
    > --------------------


    Heh.... it probably wants to write to /dev/console, and you have no rights.

    > If I want a program that I make to beep how do I do it without superuser
    > privileges?


    It is an interesting linux design decision. To make a beep as user you
    need a terminal and output to it. You do not have access to the built-in
    speaker as in MsDOS, where I had programs that made it speak. Literally.

    In Linux, access to the built-in speaker is made by the terminal, no
    controlling of it. Only "beep", and only if you do have a terminal.

    To do without a terminal, they use /dev/console... and for that, you
    need to be root, as you found out.

    Code:
    Telcontar:~ # l /dev/console
    crw------- 1 root root 5, 1 Jan  7 14:59 /dev/console
    Telcontar:~ #
    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.3 x86_64 "Dartmouth" at Telcontar)

  3. #3

    Default AW: How to make your computer beep

    Quote Originally Posted by ballsystemlord View Post
    Why do I need superuser privileges?
    If I want a program that I make to beep how do I do it without superuser privileges?
    Well, you can configure KDE to beep the speaker for messages as user.
    That's the function that is called if you press the "Test" button in KDE's settings:
    Code:
    void KBellConfig::ringBell(){
      if (!m_useBell->isChecked()) {
        KNotification::beep(QString(), this);
        return;
      }
    
    
      // store the old state
      XKeyboardState old_state;
      XGetKeyboardControl(QX11Info::display(), &old_state);
    
    
      // switch to the test state
      XKeyboardControl kbd;
      kbd.bell_percent = m_volume->value();
      kbd.bell_pitch = m_pitch->value();
      if (m_volume->value() > 0)
        kbd.bell_duration = m_duration->value();
      else
        kbd.bell_duration = 0;
      XChangeKeyboardControl(QX11Info::display(),
                             KBBellPercent | KBBellPitch | KBBellDuration,
                             &kbd);
      // ring bell
      XBell(QX11Info::display(),0);
    
    
      // restore old state
      kbd.bell_percent = old_state.bell_percent;
      kbd.bell_pitch = old_state.bell_pitch;
      kbd.bell_duration = old_state.bell_duration;
      XChangeKeyboardControl(QX11Info::display(),
                             KBBellPercent | KBBellPitch | KBBellDuration,
                             &kbd);
    }
    So have a look at "man XBell".

    But this would only work when X is running of course.

  4. #4
    Join Date
    Aug 2011
    Location
    usa
    Posts
    232

    Default Re: How to make your computer beep

    Quote Originally Posted by robin_listas View Post
    On 2014-01-11 21:06, ballsystemlord wrote:
    > So I wrote a short C program.
    >


    > It did not beep.


    I know...

    > A few days later I was going through interesting man pages and came upon
    > busy box.
    > It also had a beep program so I used it.
    >
    >
    > Code:
    > --------------------
    >
    > $busybox beep
    > beep: can't open console
    > --------------------


    Heh.... it probably wants to write to /dev/console, and you have no rights.

    > If I want a program that I make to beep how do I do it without superuser
    > privileges?


    It is an interesting linux design decision. To make a beep as user you
    need a terminal and output to it. You do not have access to the built-in
    speaker as in MsDOS, where I had programs that made it speak. Literally.

    In Linux, access to the built-in speaker is made by the terminal, no
    controlling of it. Only "beep", and only if you do have a terminal.

    To do without a terminal, they use /dev/console... and for that, you
    need to be root, as you found out.

    Code:
    Telcontar:~ # l /dev/console
    crw------- 1 root root 5, 1 Jan  7 14:59 /dev/console
    Telcontar:~ #
    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.3 x86_64 "Dartmouth" at Telcontar)
    This is all very interesting but I don't understand how it helps me create a program that beeps. Should I create my program to allocate a terminal?

  5. #5
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make your computer beep

    On 2014-02-05 18:16, ballsystemlord wrote:

    > This is all very interesting but I don't understand how it helps me
    > create a program that beeps. Should I create my program to allocate a
    > terminal?


    I tell you what I know, and how difficult it is.

    For example, I write programs in Pascal (Lazarus). The beep function
    call of it does not work, or was removed, because _they_ did not find a
    way to make it work in Linux.


    --
    Cheers / Saludos,

    Carlos E. R.

    (from 13.1 x86_64 "Bottle" (Minas Tirith))

  6. #6
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    23,699
    Blog Entries
    1

    Default Re: How to make your computer beep

    Well, of course if you have an X-session running then you can write to /dev/tty7 as the (user logged in)
    Code:
    beep > /dev/tty7
    and other tty devices if the user is a member of the 'tty' group (for write access).

    Beep is just an alias
    Code:
     type beep
    beep is aliased to `echo -en "\007"'
    so 'echo -en "\007" > /dev/ttyx' will work too.
    Last edited by deano_ferrari; 05-Feb-2014 at 21:59.

  7. #7
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make your computer beep

    On 2014-02-06 06:06, deano ferrari wrote:
    >
    > Well, of course if you have an X-session running then you can write to
    > /dev/tty7 as the (user logged in)
    >
    > Code:
    > --------------------
    > beep > /dev/tty7
    > --------------------


    Code:
    cer@minas-tirith:~> beep > /dev/tty7
    bash: /dev/tty7: Permission denied
    cer@minas-tirith:~>
    cer@minas-tirith:~> l /dev/tty7
    crw--w---- 1 root tty 4, 7 Feb  2 19:59 /dev/tty7
    cer@minas-tirith:~>
    Yes, I'm on tty7.

    --
    Cheers / Saludos,

    Carlos E. R.

    (from 13.1 x86_64 "Bottle" (Minas Tirith))

  8. #8
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    23,699
    Blog Entries
    1

    Default Re: How to make your computer beep

    Code:
    cer@minas-tirith:~> beep > /dev/tty7
    bash: /dev/tty7: Permission denied
    cer@minas-tirith:~>
    cer@minas-tirith:~> l /dev/tty7
    crw--w---- 1 root tty 4, 7 Feb  2 19:59 /dev/tty7
    cer@minas-tirith:~>
    Yes, I'm on tty7.

    --
    Cheers / Saludos,

    Carlos E. R.

    (from 13.1 x86_64 "Bottle" (Minas Tirith))
    A ownership of the tty should be assigned to the current user

    For example
    Code:
     l /dev/tty7
    crw--w---- 1 dean tty 4, 7 Feb  7 06:13 /dev/tty7

  9. #9
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make your computer beep

    On 2014-02-06 18:36, deano ferrari wrote:

    > A ownership of the tty should be assigned to the current user


    By whom? It is not automatic. My system does not do it.

    --
    Cheers / Saludos,

    Carlos E. R.

    (from 13.1 x86_64 "Bottle" (Minas Tirith))

  10. #10
    Join Date
    Jun 2008
    Location
    Auckland, NZ
    Posts
    23,699
    Blog Entries
    1

    Default Re: How to make your computer beep

    Quote Originally Posted by robin_listas View Post
    On 2014-02-06 18:36, deano ferrari wrote:

    > A ownership of the tty should be assigned to the current user


    By whom? It is not automatic. My system does not do it.

    --
    Cheers / Saludos,

    Carlos E. R.

    (from 13.1 x86_64 "Bottle" (Minas Tirith))
    If you log into a particular tty as a user, then that user should be assigned ownership as my output showed (eg I'm logged into KDE on local machine which gives me /dev/tty7). What happens if you do CTRL+ALT+F2 (for /dev/tty2) and log in as user? I get
    Code:
    l /dev/tty2
    crw--w---- 1 dean tty 4, 2 Feb  7 06:16 /dev/tty2

Page 1 of 5 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •