signal()的用法

supper08 2008-03-13 05:01:37
谁帮我解释下signal()函数的用法
...全文
253 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
supper08 2008-03-13
  • 打赏
  • 举报
回复
有点复杂
冷月清晖 2008-03-13
  • 打赏
  • 举报
回复
学习:http://www.vckbase.com/document/viewdoc/?id=1363
qiuqiu173 2008-03-13
  • 打赏
  • 举报
回复
函数名: signal
头文件: <signal.h>
功 能: 设置某一信号的对应动作
用 法: int signal(int sig, sigfun fname);
程序例:

/* This example installs a signal handler routine for SIGFPE,
catches an integer overflow condition, makes an adjustment
to AX register, and returns. This example program MAY cause
your computer to crash, and will produce runtime errors
depending on which memory model is used.
*/

#pragma inline
#include <stdio.h>
#include <signal.h>

void Catcher(int sig, int type, int *reglist)
{
printf("Caught it!\n");
*(reglist + 8) = 3; /* make return AX = 3 */
}

int main(void)
{
signal(SIGFPE, Catcher);
asm mov ax,07FFFH /* AX = 32767 */
asm inc ax /* cause overflow */
asm into /* activate handler */

/* The handler set AX to 3 on return. If that hadn't happened,
there would have been another exception when the next 'into'
was executed after the 'dec' instruction. */
asm dec ax /* no overflow now */
asm into /* doesn't activate */
return 0;
}

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧