首页 技术 正文
技术 2022年11月23日
0 收藏 732 点赞 2,258 浏览 893 个字
  • 因测试需要加入开机次数记录,所以记录一下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 \n", 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
上一篇: SVN文件排除
下一篇: PS中进程状态
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,962
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781