zoukankan      html  css  js  c++  java
  • am335x 无屏实现开关机程序

    • 因测试需要加入开机次数记录,所以记录一下7816开关机是怎么做的

    • 原理很简单,开机时判断一个记录文件是否存在,如果存在,运行一段代码,将记录开机次数文件的值读出来+1

    • 代码如下:

        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <unistd.h>
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <fcntl.h>
        #include <errno.h>
    
        int main(void)
        {
    
            int on_off_fd, count = 0, retval;
    
            on_off_fd = open("/on-off.file", O_RDWR );
    
            if (on_off_fd < 0)
            {   
                perror("on-off.file");
                return 0;
            }   
    
            retval = read(on_off_fd, &count, 4); 
            count++;
            lseek(on_off_fd, SEEK_SET, 0); 
            retval = write(on_off_fd, &count, 4); 
            if (retval < 0)
            {
                perror("write of-off count error");
            }
    
            lseek(on_off_fd, SEEK_SET, 0);
            retval = read(on_off_fd, &count, 4);
            if(retval > 0)
            {
                printf(" on-off count : %d 
    ", count);
            }
    
            close(on_off_fd);
            system("sync");
            return 0;
        }
    
        # 位置为  etc/init.d/S90aplex
        # 将上面那个文件编译出来 名字为 on-off,在开机的时候作如下判断并执行: 
        if [ -e /on-off.file ]; then
             on-off
        fi
    
        # 如果要开启关闭开机次数记录,可运行如下脚本
        #!/bin/sh
    
        if [ $1 = "start" ]; then
            touch /on-off.file
            sync
        elif [ $1 = "end"  ];then
            rm /on-off.file -rf 
            sync
        else
            echo please input "start" or "end" ;
        fi
    
  • 相关阅读:
    什么是进程
    进程控制
    MMAP文件内存映射
    I/O多路转接模型
    LINUX创建管道文件
    文件描述符复制
    LINUX改变文件大小
    类作用域
    LINUX文件定位
    War of the Corporations CodeForces
  • 原文地址:https://www.cnblogs.com/chenfulin5/p/6912885.html
Copyright © 2011-2022 走看看