preread.c
来自「arm linux 平台下的watchdog程序,C语言代码」· C语言 代码 · 共 49 行
C
49 行
#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
void feeldog(int fd)
{
while(1)
{
sleep(1);
write(fd,NULL,NULL);
}
}
void main()
{
pthread_t id; /*线程的ID*/
int fd;
int rt; /*线程的描述符*/
int i ;
/*打开看门狗设备*/
fd=open("/dev/watchdog",O_RDWR);
if(fd<0)
printf("open dev err:\n");
//创建线程
rt=pthread_create(&id,NULL,(void *)feeldog,fd);
if(rt!=0)
{
printf("create pthread err !\n");
}
while(1)
{
/*这是个死循环,
目的是为了不让进程结束
线程可以一直喂狗
*/
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?