首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言中Linux上信号有关问题

2012-08-01 
C语言中Linux下信号问题#include sys/types.h#include signal.h#include stdio.h#include stdlib.h

C语言中Linux下信号问题
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

static void sig_cld();

int main()
{
pid_t pid;

if(signal(SIGCLD, sig_cld)==-1)
{
perror("signal error");
}

if((pid=fork())<0)
{
perror("fork error");
}
else if(pid==0)
{
slee(2);
_exit(0);
}

pause();
exit();
}

static void sig_cld(void)
{
pid_t pid;
int status;

printf("SIGCLD received\n");
if(signal(SIGCLD, sig_cld)==-1)
{
perror("signal error");
}

if((pid=wait(&status))<0)
{
perror("wait error");
}
printf("pid=%d\n", pid);

return;
}

出错信息如下:

t3.c: In function ‘main’:
t3.c:12: warning: comparison between pointer and integer
t3.c:24: warning: incompatible implicit declaration of built-in function ‘_exit’
t3.c:28: error: too few arguments to function ‘exit’
t3.c: In function ‘sig_cld’:
t3.c:37: warning: passing argument 2 of ‘signal’ from incompatible pointer type
/usr/include/signal.h:101: note: expected ‘__sighandler_t’ but argument is of type ‘void (*)(void)’
t3.c:37: warning: comparison between pointer and integer

对这个不理解,希望解释一下,谢谢!

[解决办法]
t3.c:28: error: too few arguments to function ‘exit’

改成
exit(0);
[解决办法]
提示都非常明显了!!t3.c第28行出错了。

exit(); --> exit(0);
[解决办法]
《Linux C编程一站式学习》

热点排行