Linux 10分钟VGA显示器自动黑屏解决方法

来源:互联网 发布:aso优化 app 编辑:程序博客网 时间:2024/04/29 23:41
1、内核层解决

将driver/char/vt.c中的blankinterval值改成0。

2、应用层解决

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>

int main()
{
    int f;
    f = open("/dev/tty1", O_RDWR);
    write(f, "\033[9;0]", 8);
    close(f);
    return 0;
}

/etc/rc.local

echo -en "\\033[9;0]" > /dev/tty1




buntu默认10分钟就会进入屏保。
 
我用的ubuntu server12.04,由于没有桌面,只能用命令。如下:
 
setterm -blank 0 //禁用屏保
 
setterm -blank 1 //1分钟后开始屏保
 
settern是系统自带的命令,的功能相当强大,具体可用setterm --help查看。
如:setterm -dump 1  //获得1屏的信息截图,
 
要获得2屏的信息截图,setterm -dump 2 即可。
 
但上面的关闭屏保命令仅适用于本屏,我暂时没有找到关于屏保设置的文件。
 
若安装了X图形界面,可用命令xset,如:
 
xset -dpms //关闭屏保
 
xset +dpms //恢复屏保
 
具体功能用法,可以xset --help查看。
 
小结:本文只简单说明了如何关闭屏保,命令的其他用法以后介绍。


/* disable console. avoid console blank automatically */
    system("echo -e \"\033[9;0]\" > /dev/tty1");
解释:
该系统调用相当于setterm -blank 0,详见setterm命令的源码,其中
/* -blank [0-60]. */
 if (opt_blank && vcterm) 
  printf("\033[9;%d]", opt_bl_min);

也可以见Vt.c (drivers\char):        case ']': /* setterm functions */

http://blog.chinaunix.net/uid-14009064-id-4115712.html


同时可以参考

我试过用

  1. setterm -frontground green -store
复制代码
但不能在REBOOT后保持。 找到了以下方法供你参考:
在 /etc/rc.local 中加入:
  1. echo -en "\\033[32m\\033[8]" > /dev/tty1
复制代码
你可以任意替换tty号码

0 0
原创粉丝点击