博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下暂停的功能实现
阅读量:4126 次
发布时间:2019-05-25

本文共 982 字,大约阅读时间需要 3 分钟。

#include 
#include
#include
#include
int scanKeyboard(){ int in; struct termios new_settings; struct termios stored_settings; tcgetattr(0,&stored_settings); new_settings = stored_settings; new_settings.c_lflag &= (~ICANON); new_settings.c_cc[VTIME] = 0; tcgetattr(0,&stored_settings); new_settings.c_cc[VMIN] = 1; tcsetattr(0,TCSANOW,&new_settings); in = getchar(); tcsetattr(0,TCSANOW,&stored_settings); return in;}int stop = 0;int stop_assist = 0;void * pthread(void *arg){ while(1){ if(scanKeyboard() == 32){ stop_assist++; if(stop_assist%2 == 1){ stop = 1; }else{ stop = 0; } } }}int main(){ pthread_t thread_id; if ((pthread_create(&thread_id, NULL, pthread, NULL)) == -1){ printf("create error!\n"); return 1; } while(stop){ sleep(1); } return 0;}

转载地址:http://jeqpi.baihongyu.com/

你可能感兴趣的文章
JAVA操作properties文件的代码实例
查看>>
IPS开发手记【一】
查看>>
Java通用字符处理类
查看>>
文件上传时生成“日期+随机数”式文件名前缀的Java代码
查看>>
Java代码检查工具Checkstyle常见输出结果
查看>>
北京十大情人分手圣地
查看>>
Android自动关机代码
查看>>
Android中启动其他Activity并返回结果
查看>>
2009年33所高校被暂停或被限制招生
查看>>
GlassFish 部署及应用入门
查看>>
iWatch报错: Authorization request cancled
查看>>
iWatch报错: Authorizationsession time out
查看>>
如何运行从网上下载的iWatch项目详细步骤.
查看>>
X-code7 beta error: warning: Is a directory
查看>>
Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.
查看>>
X-code beta 开发iWatch项目,运行没有错误,但是某些操作一点就崩,而且找不错误的原因场景一
查看>>
Xcode 报错: Extra argument in call
查看>>
iTunes Connect 上传APP报错: Communication error. please use diagnostic mode to check connectivity.
查看>>
#import <Cocoa/Cocoa.h> 报错 Lexical or Preprocessor Issue 'Cocoa/Cocoa.h' file not found
查看>>
`MQTTClient (~> 0.2.6)` required by `Podfile`
查看>>