1. 如何让程序后台执行
使用“&”符号,./led_player&
在终端中启动程序后,终端后还可以继续输入
2. 让输出立即刷新到终端
fprintf(stdout, "\nInput light level: %d \n",led_lev);
while(1){
。。。
}
发现fprintf()没能输出,推测终端可能不是立即刷新的,在网上搜了下果然是这样,添加一句话
fflush(stdout);
3 .在程序执行过程中输入
在程序过程中调用fscanf()输入,发现程序停止了执行,在一直等待输入;
while(1){
if(fscanf(stdin, "%d", &new_lev) == 1)
{。。。。}
。。。。。。
}
本来while中是一个led扫描的操作,结果扫描停止了。无奈,只好加了一个新的线程
if (pthread_create(&input_tid,NULL,thrd_input,NULL)!=0) {
printf("Create thread error!\n");
exit(1);
}
while(1){
。。。
}
4 .线程编译
使用线程时要先声明头文件:
#include <pthread.h>
编译时,l链接 lpthread 库:
arm-linux-gcc -lpthread -o $(filename) $(filename).c
待续。。。。