|
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- void sig_arm(int signo);
- sighandler_t my_signal(int signo, sighandler_t func); //编译报错
- void sig_arm(int signo)
- {
- alarm(10);
- printf("signal:%d \n", signo);
- }
- //自定义的signal
- sighandler_t my_signal(int signo, sighandler_t func)//编译报错
- {
- struct sigaction act, oct;
- act.sa_hander = func;
- act.sa_flags = 0;
- sigemptyset(&act.sa_mask);
- act.sa_flags |= SA_INTERRUPT;
- if(sigaction(signo, &act, &oct) < 0)
- {
- printf("register signal error");
- return SIG_ERR;
- }
- return oct.sa_hander;
- }
- int main()
- {
- char s[100];
- int n;
- if(my_signal(SIGALRM, sig_arm) == SIG_ERR)//编译报错
- {
- printf("register signal error");
- }
- alarm(10);
- if((n=read(STDIN_FILENO, s, 100)) < 0)
- {
- printf("read error \n");
- }
- alarm(0);
- printf("you input is %s \n", s);
- }
- -----------------------------------------------------
- 在fedora 9下编译错误如下:
- test3.c:6: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘my_signal’
- test3.c: 在函数‘main’中:
- test3.c:18: 警告:比较指针和整数
- test3.c: 在文件层:
- test3.c:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘my_signal’
- -----------------------------------------------------
- 望各位指点。。。。在此谢过。。(环境:fedora 9, gcc 4.3)
复制代码 |
|