⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console6.txt

📁 linux/kd.h文件中介绍了ioctl函数能够使用的命令
💻 TXT
字号:
Example:
        Note, this flashes the LEDs as well for effect, they aren't needed
  here.

	#include <stdio.h>
	#include <fcntl.h>
	#include <unistd.h>
	#include <signal.h>
	#include <sys/stat.h>
	#include <linux/kd.h>
	#include <sys/types.h>
	#include <sys/ioctl.h>

	#define ERROR -1

	int fd;

	void sighandler(int signum);

	void main()
	{
	  int lednum;
	  int i, j, k;

          /* To be used as the fd in ioctl(). */
	  if ((fd = open("/dev/console", O_NOCTTY)) == ERROR) {
	     perror("open");
	     exit(ERROR);
	  }

	  printf("w00w00!.\n\n");

          /* We don't want an LED still on after we quit. */
	  signal(SIGINT,  sighandler);
	  signal(SIGTERM, sighandler);
	  signal(SIGQUIT, sighandler);
	  signal(SIGTSTP, sighandler);

	  printf("For the best sounding one, use the example values shown.\n");
	  printf("To exit hit Control-C.\n");

	  while (1) {
	     printf("Enter range of tones to play (i.e. 100-3000): ");
	     scanf("%d%*c%d", &i, &j);

	     printf("Enter intervals to skip (i.e. 10): ");
	     scanf("%d", &k);

             printf("Doing %d through %d, with an interval of %d:\n\n", 
                    i, j, k);

             for (; i <= j; i += k) {
                for (lednum = 0x01; lednum <= 0x04; lednum++) {
                   if (lednum == 0x03) continue;

                   usleep(10000);

                   if ((ioctl(fd, KDSETLED, lednum)) == ERROR) {
                      perror("ioctl");
                      close(fd);
                      exit(ERROR);
                   }

                }

                if ((ioctl(fd, KIOCSOUND, i)) == ERROR) {
                   perror("ioctl");
                   close(fd);
                   exit(ERROR);
                }

                printf("%d\n", i);
                if (i == j) break;

                usleep(70000);

             }

             /* Turn off all sound. */
             if ((ioctl(fd, KIOCSOUND, 0x0)) == ERROR) {
                perror("ioctl");
                close(fd);
                exit(ERROR);
             }

             /* Turn off all leds. */
             if ((ioctl(fd, KDSETLED, 0x0)) == ERROR) {
                perror("ioctl");
                close(fd);
                exit(ERROR);
             }

             putchar('\n');
          }

          close(fd); /* Will never get this far. */
        }

	void sighandler(int signum)
	{
  	  /* Stop all sound. */
  	  if ((ioctl(fd, KIOCSOUND, 0x0)) == ERROR) { 
	     perror("ioctl");
	     close(fd);
    	     exit(ERROR);
          }

          /* Turn off all leds. */
          if ((ioctl(fd, KDSETLED, 0x0)) == ERROR) { 
             perror("ioctl");
             close(fd);
             exit(ERROR);
          }

          printf("\nw00w00!\n");
          close(fd);
          exit(0);
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -