69,371
社区成员
发帖
与我相关
我的任务
分享
s=getch(); 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <signal.h>
5 #include <time.h>
6
7 int sys_err(char *str)
8 {
9 puts(str);
10 exit(0);
11 }
12
13 void sig_usr(int a)
14 {
15 exit(0);
16 }
17
18 int main(void)
19 {
20 char str[100];
21 pid_t pid;
22
23 if((pid=fork()) < 0)
24 sys_err("fork error");
25 else if(pid == 0)
26 {
27 if(signal(SIGUSR1, sig_usr) == SIG_ERR)
28 sys_err("signal error");
29 sleep(5);
30 kill(getppid(), SIGKILL);
31 }
32 else
33 {
34 scanf("%99s", str);
35 kill(pid, SIGUSR1);
36 puts("\nis OK, input is:");
37 puts(str);
38 }
39 return 0;
40 }
#include <stdlib.h>#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define MT 600000
int main(void)
{
int flag=0;
char c;
while (!kbhit()) //如果键盘有动作,则退出
{
/*
如果你使用的是TC这个你可以直接使用delay(MT);
如果不是,直接写一个延迟程序,用二重循环来
mydelay(MT);
*/
flag = 1; //时间到了,标志位置1
if (flag)
break;
}
if (flag)
printf("没有按键按下");
else
{
c = getch(); //用以接受你刚才的按键
printf("有"); //可换成你的要执行的块
/*
加入你的执行块
*/
}
return 0;
}