我有 2 份简单的工作。第一个是从管道读取。第二是通过超时做一些操作。问题是让它在一个过程中工作(我知道如何在两个过程中做到这一点,但它不适合我..)。
并且有一些理由不使用 cron。2 个作业应该异步运行(互不阻塞)。
有任何想法吗?
#include<stdio.h>
#include<stdlib.h>
void someAnotherJob();
main(){
printf ("Hello!\n");
int c;
FILE *file, *file2;
file = fopen("/dev/ttyUSB0", "r");
file2 = fopen("out.txt", "a");
if (file) {
while ((c = getc(file)) != EOF){
fputc(c, file2);
fflush(file2);
}
fclose(file);
}
while (1) {
someAnotherJob();
sleep(10);
}
}
void someAnotherJob()
{
printf("Yii\n");
}