2010年6月4日 星期五

使用蜂鳴器通知某指令完成

1.先寫一隻能夠使蜂鳴器發出聲音的程式

//b2.c
#include
#include

void play(unsigned int* freq, unsigned int* delay);

int main(int argc, char* argv[])
{
speaker(330, 5);
speaker( 0, 5);
speaker(330, 5);

return 0;
}

int speaker(unsigned int freq,unsigned int delay)
{ static int flag=0,bit;
if(flag==0)
{
flag=1;
iopl(3);
}
outb(0xb6,0x43);
outb((freq & 0xff),0x42);
outb((freq >> 8),0x42);
bit=inb(0x61);
outb(3 | bit,0x61);
usleep(10000*delay);
outb(0xfc | bit,0x61);
return;
}


2.beep:一個shell script使b2在指令完成時執行

$*
sudo ./b2


3.把b2 and beep放至/bin

4.由於b2發出聲音要有root的權限,所以b2擁有者要設為root,然後對beep作setuid
http://www.google.com/url?q=http%3A%2F%2Flinux.vbird.org%2Flinux_basic%2F0220filemanager.php%23suid&sa=D&sntz=1&usg=AFrqEzfx6HcqK_4BpogqAlU2s7Ts5ttsug

沒有留言: