linux下C++写了个看门狗程序,Ctrl+C终止,系统重起后文件长度变0了。怎么回事啊
linux下C++写了个看门狗程序,Ctrl+C终止,系统重起后文件长度变0了。怎么回事啊
[解决办法]
怎么觉得是磁盘出现问题了?
[解决办法]
直接重启没事?程序是存在硬盘还是U盘或着时FLASH?
[解决办法]
x86系统,硬盘是cf卡
[解决办法]
直接重启文件长度还是0
[解决办法]
CC编译就没问题
GCC就这样
//============================================================================
// Name : main.cpp
// Author : superman
// Version :
// Copyright : copy right by wangliang
// Description : APSite Control, Ansi-style
//============================================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
#include <sys/signal.h>
#include <termios.h>
struct watchdog_info{
unsigned int options; //options the card/driver supprots 19
unsigned int firmware_version; //firmcard version of the card
unsigned char identity[32]; //identity of the board 21
};
#define WATCHDOG_IOCTL_BASE 'W'
#define WDIOC_GETSUPPORT _IOR(WATCHDOG_IOCTL_BASE, 0, struct watchdog_info)
#define WDIOC_SETTIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
#define WDIOC_GETTIMEOUT _IOR(WATCHDOG_IOCTL_BASE, 7, int)
#define WDIOS_DISABLECARD 0x0001 /* Turn off the watchdog timer */
#define WDIOS_ENABLECARD 0x0002 /* Turn on the watchdog timer */
#define WDIOC_SETOPTIONS _IOR(WATCHDOG_IOCTL_BASE, 4, int)
#define WDIOC_KEEPALIVE _IOR(WATCHDOG_IOCTL_BASE, 5, int)
int Getch (void) //无回显的从屏幕输入字符,来达到喂狗的目的
{
int ch;
struct termios oldt, newt; //终端设备结构体
tcgetattr(STDIN_FILENO, &oldt); //获得终端属性
newt = oldt;
newt.c_lflag &= ~(ECHO