¡¡¡¡ÓÉÓÚÕâЩÎļþ²»ÊÇÆÕͨµÄÎļþ£¬ËùÒÔÎÒÃDz»ÄÜÓÃANSI C£¨±ê×¼C£©µÄfopen¡¢fcloseµÈÀ´²Ù×÷Îļþ£¬¶øÓ¦¸ÃʹÓÃϵͳÎļþI/O´¦Àíº¯Êý£¨open¡¢read¡¢write¡¢lseekºÍclose£©À´´¦ÀíÕâЩÉ豸Îļþ¡£ioctl£¨£©»òÐíÊÇLinuxÏÂ×îÅÓÔӵĺ¯Êý£¬Ëü¿ÉÒÔ¿ØÖƸ÷ÖÖÎļþµÄÊôÐÔ£¬ÔÚLinuxÉùÒôÉ豸±à³ÌÖУ¬×îÖØÒªµÄ¾ÍÊÇʹÓô˺¯ÊýÕýÈ·ÉèÖñØÒªµÄ²ÎÊý¡£
¡¡¡¡ÏÂÃæÎÒÃǾÙÁ½¸öʵ¼ÊµÄÀý×ÓÀ´ËµÃ÷ÈçºÎʵÏÖLinuxϵÄÉùÒô±à³Ì¡£ÓÉÓÚ´ËÀà±à³ÌÉæ¼°µ½ÏµÍ³É豸µÄ¶Áд£¬ËùÒÔ£¬ºÜ¶àʱºòÐèÒªÄãÓÐrootȨÏÞ£¬Èç¹ûÄ㽫ÏÂÃæµÄÀý×Ó±àÒëºó²»ÄÜÕýÈ·Ö´ÐУ¬ÄÇô£¬Ê×ÏÈÇëÄã¼ì²éÊÇ·ñÊÇÒòΪûÓвÙ×Ýij¸öÉ豸µÄȨÏÞ¡£
¡¡¡¡¶ÔÄÚ²¿ÑïÉùÆ÷±à³ÌÄÚ²¿ÑïÉùÆ÷ÊÇ¿ØÖÆ̨µÄÒ»²¿·Ö£¬ËùÒÔËü¶ÔÓ¦µÄÉ豸ÎļþΪ/dev/console¡£±äÁ¿KIOCSOUNDÔÚÍ·Îļþ /usr /include /linux /kd.hÖÐÉùÃ÷£¬ioctlº¯ÊýʹÓÃËü¿ÉÒÔÀ´¿ØÖÆÑïÉùÆ÷µÄ·¢Éù£¬Ê¹ÓùæÔòΪ£º
ÒýÓÃ:¡¡¡¡ioctl ( fd, KIOCSOUND, (int) tone);
¡¡¡¡fdΪÎļþÉ豸ºÅ£¬tone ÊÇÒôƵֵ¡£µ±toneΪ0ʱ£¬ÖÕÖ¹·¢Éù¡£±ØÐëÒ»ÌáµÄÊÇËüËùÀí½âµÄÒôƵºÍÎÒÃÇƽ³£ÒÔΪµÄÒôƵÊDz»Í¬µÄ£¬ÓÉÓÚ¼ÆËã»úÖ÷°å¶¨Ê±Æ÷µÄʱÖÓƵÂÊΪ1.19MHZ£¬ËùÒÔÒª½øÐÐÕýÈ·µÄ·¢Éù£¬±ØÐë½øÐÐÈçϵÄת»»£ºÑïÉùÆ÷ÒôƵֵ=1190000/ÎÒÃÇÆÚÍûµÄÒôƵֵ¡£
¡¡¡¡ÑïÉùÆ÷·¢Éùʱ¼äµÄ³¤¶ÌÎÒÃÇͨ¹ýº¯Êýusleep£¨unsigned long usec£©À´¿ØÖÆ¡£ËüÊÇÔÚÍ·Îļþ/usr /include /unistd.hÖж¨ÒåµÄ£¬ÈóÌÐò˯Ãßusec΢Ãë¡£ÏÂÃæ¼´ÊÇÈÃÑïÉùÆ÷°´Ö¸¶¨µÄ³¤¶ÈºÍÒôƵ·¢ÉùµÄ³ÌÐòµÄÍêÕûÇåµ¥£º
ÒýÓÃ:#include < fcntl.h >
#include < stdio.h >
#include < stdlib.h >
#include < string.h >
#include < unistd.h >
#include < sys/ioctl.h >
#include < sys/types.h >
#include < linux/kd.h >
/* É趨ĬÈÏÖµ */
#define DEFAULT_FREQ 440 /* É趨һ¸öºÏÊʵÄƵÂÊ */
#define DEFAULT_LENGTH 200 /* 200 ΢Ã룬·¢ÉùµÄ³¤¶ÈÊÇÒÔ΢ÃëΪµ¥Î»µÄ*/
#define DEFAULT_REPS 1 /* ĬÈϲ»Öظ´·¢Éù */
#define DEFAULT_DELAY 100 /* ͬÑùÒÔ΢ÃëΪµ¥Î»*/
/* ¶¨ÒåÒ»¸ö½á¹¹£¬´æ´¢ËùÐèµÄÊý¾Ý*/
typedef struct {
int freq; /* ÎÒÃÇÆÚÍûÊä³öµÄƵÂÊ£¬µ¥Î»ÎªHz */
int length; /* ·¢Éù³¤¶È£¬ÒÔ΢ÃëΪµ¥Î»*/
int reps; /* Öظ´µÄ´ÎÊý*/
int delay; /* Á½´Î·¢Éù¼ä¸ô£¬ÒÔ΢ÃëΪµ¥Î»*/
} beep_parms_t;
/* ´òÓ¡°ïÖúÐÅÏ¢²¢Í˳ö*/
void usage_bail ( const char *executable_name ) {
printf ( "Usage: \n \t%s [-f frequency] [-l length] [-r reps] [-d delay] \n ",
executable_name );
exit(1);
}
/ * ·ÖÎöÔËÐвÎÊý£¬¸÷ÏîÒâÒåÈçÏ£º
* "-f <ÒÔHZΪµ¥Î»µÄƵÂÊÖµ >"
* "-l <ÒÔºÁÃëΪµ¥Î»µÄ·¢Éùʱ³¤ >"
* "-r <Öظ´´ÎÊý >"
* "-d <ÒÔºÁÃëΪµ¥Î»µÄ¼äЪʱ³¤ >"
*/
void parse_command_line(char **argv, beep_parms_t *result) {
char *arg0 = *(argv++);
while ( *argv ) {
if ( !strcmp( *argv,"-f" )) { /*ƵÂÊ*/
int freq = atoi ( *( ++argv ) );
if ( ( freq <= 0 ) | | ( freq > 10000 ) ) {
fprintf ( stderr, "Bad parameter: frequency must be from 1..10000\n" );
exit (1) ;
} else {
result->freq = freq;
argv++;
}
} else if ( ! strcmp ( *argv, "-l" ) ) { /*ʱ³¤*/
int length = atoi ( *(++argv ) );
if (length < 0) {
fprintf(stderr, "Bad parameter: length must be >= 0\n");
exit(1);
} else {
result->length = length;
argv++;
}
} else if (!strcmp(*argv, "-r")) { /*Öظ´´ÎÊý*/
int reps = atoi(*(++argv));
if (reps < 0) {
fprintf(stderr, "Bad parameter: reps must be >= 0\n");
exit(1);
} else {
result->reps = reps;
argv++;
}
} else if (!strcmp(*argv, "-d")) { /* ÑÓʱ */
int delay = atoi(*(++argv));
if (delay < 0) {
fprintf(stderr, "Bad parameter: delay must be >= 0\n");
exit(1);
} else {
result->delay = delay;
argv++;
}
} else {
fprintf(stderr, "Bad parameter: %s\n", *argv);
usage_bail(arg0);
}
}
}
int main(int argc, char **argv) {
int console_fd;
int i; /* Ñ»·¼ÆÊýÆ÷ */
/* Éè·¢Éù²ÎÊýΪĬÈÏÖµ*/
beep_parms_t parms = {DEFAULT_FREQ, DEFAULT_LENGTH, DEFAULT_REPS,
DEFAULT_DELAY};
/* ·ÖÎö²ÎÊý£¬¿ÉÄܵĻ°¸üз¢Éù²ÎÊý*/
parse_command_line(argv, &parms);
/* ´ò¿ª¿ØÖÆ̨£¬Ê§°ÜÔò½áÊø³ÌÐò*/
if ( ( console_fd = open ( "/dev/console", O_WRONLY ) ) == -1 ) {
fprintf(stderr, "Failed to open console.\n");
perror("open");
exit(1);
}
/* ÕæÕý¿ªÊ¼ÈÃÑïÉùÆ÷·¢Éù*/
for (i = 0; i < parms.reps; i++) {
/* Êý×Ö1190000´ÓºÎ¶øÀ´£¬²»µÃ¶øÖª*/
int magical_fairy_number = 1190000/parms.freq;
ioctl(console_fd, KIOCSOUND, magical_fairy_number); /* ¿ªÊ¼·¢Éù */
usleep(1000*parms.length); /*µÈ´ý... */
ioctl(console_fd, KIOCSOUND, 0); /* Í£Ö¹·¢Éù*/
usleep(1000*parms.delay); /* µÈ´ý... */
} /* Öظ´²¥·Å*/
return EXIT_SUCCESS;
}
¡¡¡¡½«ÉÏÃæµÄÀý×ÓÉÔ×÷À©Õ¹£¬Óû§¼´¿ÉÒÔÈÃÑïÉùÆ÷³ª¸è¡£Ö»ÒªÕÒµ½ÎåÏßÆ×»ò¼òÆ×µÄÒô½×¡¢Òô³¤¡¢½ÚÅĺÍƵÂÊ¡¢·¢Éùʱ³¤¡¢¼ä¸ôµÄ¶ÔÓ¦¹Øϵ¾Í¿ÉÒÔÁË¡£ÎÒÏÖÔÚ»¹¼ÇµÃÒÔÇ°ÔÚDOSϱàд³ö¡¶ÊÀÉÏÖ»ÓÐÂèÂèºÃ¡·Ê±µÄÐË·Ü¡£×îºó£¬ËµÒ»Ð©ÌáÍâ»°£¬ÕâÆäʵÊÇÒ»¸öºÜ¼òµ¥µÄ³ÌÐò£¬µ«ÊÇÎÒÃÇÈ´ÓÃÁ˺ܳ¤µÄƪ·ù£¬Ï£Íû¶ÁÕß´ÓÒÔÉϵĴúÂëÀïÄÜÌå»áµ½Ð´ºÃµÄ³ÌÐòµÄһЩ·½·¨£¬»òÐí×îÖØÒªµÄÊÇÌí¼Ó×¢ÊÍ°É¡£Ò»¸ö³ÌÐòµÄ×¢ÊÍÓÀÔ¶²»»áÏӶ࣬¼´±ãÄãдµÄʱºò¾õµÃËü¸ù±¾ÊǶàÓ࣬µ«ÏàÐÅÎÒ£¬ÏàÐÅÔøÕâÑù¸æËßÎÒÃǵÄÐí¶àÓÅÐãµÄ³ÌÐòÔ±£ºÑø³ÉдºÜ¶à×¢Ê͵ÄÏ°¹ß¡£
72.36.211.* ÓÚ 2007-04-23 05:42:29·¢±í:
Nice site!
24 ringtone | mobile ringtones | sanyo ringtones | ringtone composer | free centennial wireless ringtones | mosquito ring tone | gospel ringtones | star wars ringtones | free mp3 download | alltel free ringtones
72.36.211.* ÓÚ 2007-04-23 05:42:11·¢±í:
Great work!
centennial ringtones | nextel ringtone program | ringtones motorola | boost mobile ringtones | free cell phone ringtones | alltel ringtones | 24 ctu ringtone verizon | free ringtones for t-mobile | free polyphonic ringtones | sprint pcs ringtones
72.36.211.* ÓÚ 2007-04-23 05:41:40·¢±í:
Great work!
real tone ringtones | free ringtones for nokia | sprint ringtones | ringtones 24 | free midi ringtone | ctu ringtone mp3 | 50 cent ringtones | free anime | voice ringtones | us cellular ringtones
72.36.211.* ÓÚ 2007-04-23 05:41:10·¢±í:
Great work!
free ringtones for tmobile | free lg ringtones | tracfone free ringtones | free wav ringtones | ringtones mp3 free | mosquito ringtone | free phone downloads | funny ringtone | download free polyphonic ringtones | ringtones free
72.36.211.* ÓÚ 2007-04-22 07:59:31·¢±í:
Well done!
slot game | no deposit casinos | strip blackjack game | free slot machines games | free slot machine game | texas holdem free online | texas hold em online | flash casino | free slot machines | casino games online
72.36.211.* ÓÚ 2007-04-22 07:59:04·¢±í:
Thank you!
absolute poker | online casino games | poker software | free texas holdem | poker game online | internet casino | no download casino | free slots for fun | free gambling | play poker for free
72.36.211.* ÓÚ 2007-04-22 07:58:39·¢±í:
Thank you!
casino game download | play slots for fun | virtual poker | internet gambling | full tilt poker | roulette download | online slot machines | free black jack | on line poker | free blackjack online
72.36.211.* ÓÚ 2007-04-22 07:58:10·¢±í:
Well done!
best poker sites | free joker poker | free slots on line | strip blackjack | free slot machine downloads | free casino games online | poker web sites | best online casinos | free strip black jack | free gambling games
72.36.211.* ÓÚ 2007-04-22 07:57:41·¢±í:
Good design!
slot machines | free online slots games | blackjack for free | slot machines games | texas holdem free | play texas hold em | blackjack download | internet casino games | play free blackjack online | strip black jack
72.36.211.* ÓÚ 2007-04-21 06:33:13·¢±í:
Nice site!
video poker machines | star poker | texas holdem poker | casino no deposit | no download casino | online casino games | free casino games online | free sim slots
72.36.211.* ÓÚ 2007-04-21 06:32:53·¢±í:
Good design!
free casino | play blackjack | omaha poker | slot machine free | free online poker games | poker games | paradise poker | free strip black jack | online bingo | free slot machine games
72.36.211.* ÓÚ 2007-04-21 06:32:22·¢±í:
Great work!
no limit texas hold em | free slots | free slots | free bingo games | black jack games | free online texas hold em | best poker sites | play blackjack online | free poker websites | free slot machine downloads
72.36.211.* ÓÚ 2007-04-21 06:32:01·¢±í:
Nice site!
free online poker | poker websites | internet blackjack | new online casinos | russian roulette games | free slots for fun | slot machine | free slot machine | online holdem | free casino money
72.36.211.* ÓÚ 2007-04-21 06:31:31·¢±í:
Great work!
free online casino game | free online casino slots | free roulette online | free slot game | flash casinos | free slot machines | free games online | play bingo online | poker machines | free money no deposit casinos
72.36.211.* ÓÚ 2007-04-20 06:16:39·¢±í:
Well done!
free casino games online | free poker money | full tilt poker | free online casino game | online strip blackjack | free online black jack | free monopoly online | bonus poker | deposit bonus casino | free strip black jack
72.36.211.* ÓÚ 2007-04-20 06:16:10·¢±í:
Thank you!
blackjack strip | poker games | internet casino | aussie slots | strip blackjack online | roulette free | play free slots | online free poker | roulette game | online poker games
72.36.211.* ÓÚ 2007-04-20 06:15:24·¢±í:
Good design!
video poker | 3 card poker | free slot play | online poker game | poker download | slots download | russian roulette | gambling games | gambling online | free video slot games
72.36.211.* ÓÚ 2007-04-20 06:14:52·¢±í:
Nice site!
free casino games | play blackjack | casino games free | online poker | free slot machine games online | blackjack free | download poker | free no deposit casinos | texas poker | online games
72.36.211.* ÓÚ 2007-04-20 06:14:21·¢±í:
Nice site!
no deposit casino bonus | online slots | free sims slots | online slot games | no deposit bingo | games on line | video slot games | three card poker | download slots | play roulette free
72.36.211.* ÓÚ 2007-04-19 07:22:29·¢±í:
Thank you!
free ringtones for samsung | nokia free download | star wars ringtone | free ringtones cingular | ringtone jukebox | free verizon ringtones | free nascar ringtones | download free polyphonic ringtones | mp3 ringtone | free ringtones for tracfones
72.36.211.* ÓÚ 2007-04-19 07:22:00·¢±í:
Thank you!
ringtone 24 | nokia ringtone | ringtones verizon | tmobile ringtones | cingular wireless ringtones | ringtones cingular | free ringtones for sprint phones | sprint pcs ringtones | free cricket ringtones | 50 cent ringtones
72.36.211.* ÓÚ 2007-04-19 07:21:37·¢±í:
Nice site!
free composer ringtones | download free ringtone | free monophonic ringtones | free wav ringtones | free downloadable ringtones | ring tones | christian music ringtones | ringtones for cingular | free mobile downloads | ringtones for alltel
72.36.211.* ÓÚ 2007-04-19 07:21:10·¢±í:
Great work!
ringtones | mobile phone ringtones | free ringtones | nascar ringtones | cingular ringtones | monophonic ringtones | ringtones free | free anime ringtones | free ringtones samsung | free ringtones for sprint
72.36.211.* ÓÚ 2007-04-19 07:20:42·¢±í:
Great work!
download free mp3 ringtones | online ringtone converter | verizon ringtones free | free motorola ringtone downloads | sanyo ringtones | free mobile ringtones | ringtones for motorola q | ringtones for suncom | ringtones mp3 | download ringtones free
72.232.250.* ÓÚ 2007-04-18 06:21:45·¢±í:
Nice site!
slots for fun | play poker for free | roulette | world series of poker download | texas holdem online | world series poker | free online strip blackjack | free slots machines | new no deposit online casinos | poker game download
72.232.27.* ÓÚ 2007-04-18 06:20:52·¢±í:
Nice site!
free blackjack online | free online black jack | usa online casino | blackjack free games | free money casino | play slots for free | free black jack game | free video slots | on line poker | free slot game
72.232.250.* ÓÚ 2007-04-18 06:19:38·¢±í:
Well done!
play texas holdem free | no download casino | free online games | free fun slots | free online casino | free casino slot | free slot games | free poker sites | free texas holdem online | poker games online
72.232.250.* ÓÚ 2007-04-18 06:19:07·¢±í:
Well done!
poker stars download | poker game free | casino download | download casino games | casino free | roulette game | poker web sites | texas hold em poker | strip blackjack games | free online slot machine
72.232.250.* ÓÚ 2007-04-18 06:18:49·¢±í:
Well done!
strip blackjack | poker games download | free poker download | black jack | casino online download | download party poker | video slot machine | free online casinos | internet bingo | play roulette
72.232.27.* ÓÚ 2007-04-17 04:57:24·¢±í:
Thank you!
superbowl bet | baseball bases | infielder baseball | best baseball player | mlb odds | nascar odds odds | football game odds | football lines | las vegas bet | sport books
72.232.250.* ÓÚ 2007-04-17 04:56:55·¢±í:
Great work!
nfl betting line | ncaa basketball pick | boxing bet bet | major league basball | betting uk | nfl futures | baseball lines | sports betting site | betting calculator | portuguese superliga bet
72.232.250.* ÓÚ 2007-04-17 04:56:29·¢±í:
Good design!
baseball statistics | odds on basketball | us bets | nhl odds | mlb odds odds | ncaa bet | hockey bets | pro baseball betting online | nfl sportsbook | ncaa betting lines
72.232.250.* ÓÚ 2007-04-17 04:55:52·¢±í:
Good design!
baseball playoff | sports bookies | nfl superbowl odds | super bowl betting odds | betting line on ncaa basketball | college betting line | sports betting pick | odds on ncaa basketball | nba picks | sports betting rules
72.232.250.* ÓÚ 2007-04-17 04:55:33·¢±í:
Well done!
online hockey betting | baseball betting odds | uefa champions league bet | sports lines | sports bet | online football betting | betting on sports | sport book | internet sports betting | live betting
72.232.27.* ÓÚ 2007-04-16 06:02:25·¢±í:
Well done!
nokia free download | star wars ringtone | cell phone ringtones | free ringtones samsung | christian ringtones | motorola mp3 | ringtones for tracfone | free ringtone | free nextel ringtones | free mobile downloads
72.232.250.* ÓÚ 2007-04-16 06:01:57·¢±í:
Well done!
free ringtone converter | free ringtones for us cellular | download free mp3 ringtones | crazy frog ringtones | free ringtones for alltel | free phone ringtones | free cingular cell phone ringtones | anime ringtones | free nascar ringtones | cingular wireless ringtones
72.232.250.* ÓÚ 2007-04-16 06:01:36·¢±í:
Thank you!
boost ringtones | free ringtones for tmobile | free mp3 download | country ringtones | ringtone mp3 | us cellular free ringtones | ringtone uploader | motorola free ringtones | free sanyo ringtones | free ringtones for cellular south
72.232.27.* ÓÚ 2007-04-16 06:01:19·¢±í:
Thank you!
free funny ringtones | ringtone motorola | ringtones for nokia | ringtones midi | ringtones samsung | nokia free ringtones | real tone ringtones | 24 ctu ringtones | free alltel ringtones | free ringtones for u s cellular
72.232.27.* ÓÚ 2007-04-16 06:01:06·¢±í:
Well done!
free ringtones lg | 24 ringtone | verizon ctu ringtone | cingular free ringtones | free real ringtones for cingular | free ringtone | t mobile ringtones | free mp3 ringtones | nascar ringtones | free motorola ringtones
72.232.27.* ÓÚ 2007-04-15 05:26:34·¢±í:
Great work!
games online | free online bingo | free internet poker | play blackjack | internet casino games | poker software | no deposit casino bonuses | free roulette online | online gambling sites | sims free slots