< signal.h中> - 关于信号的问题 [英] <signal.h> - question about signals

查看:80
本文介绍了< signal.h中> - 关于信号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道何时以及如何使用信号(例如SIGFPE,SIGABRT,

SIGTERM,SIGSEGV,SIGINT)?非常感谢你。

解决方案

" Jackie" < JA ********** @ earthlink.net>在消息新闻中写道:< l _ ************** @ newsread2.news.pas.earthlin k.net> ...

大家好,


您好!

我想知道何时以及如何使用信号(例如SIGFPE,SIGABRT,
SIGTERM,SIGSEGV,SIGINT)?非常感谢你。




信号提供了处理异步(和意外)事件的方法。

信号(数字)与一个事件。例如:


SIGFPE:与事件浮点错误(FPE)相关联。对于

示例:当进程尝试将数字除以零时发生这种情况

,如p = 5/0。


SIGSEGV:与事件段违规相关联。当进程试图访问非法内存段时生成

(这是带指针的常见错误

)。


SIGINT:当终端按下

中断键(通常是Ctrl + C)时,由终端(控制台)生成。


每个信号都有关联默认动作,发生在生成信号的时候。但是这可以使用

信号函数之一(如signal(),sigaction())来改变。这些函数允许我们指定用户定义的动作(函数)来处理信号。

现在安装我们自己的处理程序后,如果信号发生..这次

将采取用户指定的操作来处理该信号。


但是有些信号无法捕捉和处理......

喜欢:SIGKILL,SIGSTOP。


Plzz参考你的系统手册了解更多信息...


- Gana


信号提供了一种处理异步(和意外)事件的方法。
信号(数字)与事件相关联。喜欢:

SIGFPE:与事件相关联的浮点错误(FPE)。对于
示例:当进程尝试将数字除以零时发生这种情况
如p = 5/0。




谢谢你很多回复。你能给我一个代码示例,显示

如何能够使用< signal.h>中的信号处理异步

(和意外​​)事件?我应该调用这个函数:" int raise(int sig)"?

我非常想知道如何在交流代码中使用信号,因为信号

是在标准库中提到。


" Jackie" < JA ********** @ earthlink.net>在消息新闻中写道:<到*************** @ newsread2.news.pas.earthli nk.net> ...

非常感谢您的回复。你能给我一个代码示例,说明如何使用< signal.h>中的信号。处理异步
(和意外)事件?我应该调用这个函数:" int raise(int sig)"
我非常想知道如何在交流代码中使用信号,因为标准库中提到了信号
。 blockquote>


这让我很困惑。即使是功能原型

需要一段时间才能搞清楚。


现在让我们看看。


void( * signal(int sig,void(* func)(int)))(int);


singal是一个带两个参数和teturning的函数

a指针函数。


参数是(1)一个int,和(2)一个指向

函数的指针,它接受一个int并且什么都不返回。 br />

返回值是指向一个函数的指针,它取一个int

并且什么都不返回。


看起来这样吗好吗?


现在,如何声明指向此信号函数的指针?


Hi everyone,
I''d like to know when and how signals are used (e.g. SIGFPE, SIGABRT,
SIGTERM, SIGSEGV, SIGINT)? Thank you so much.

解决方案

"Jackie" <Ja**********@earthlink.net> wrote in message news:<l_**************@newsread2.news.pas.earthlin k.net>...

Hi everyone,
Hello!
I''d like to know when and how signals are used (e.g. SIGFPE, SIGABRT,
SIGTERM, SIGSEGV, SIGINT)? Thank you so much.



Signals provide a way to handle asynchronous (and unexpected) events.
A signal (number) is associated with an event. Like:

SIGFPE: associated with the event "Floating Point Error (FPE)". For
example: This occurs when the process tries to divide a number by zero
as in p=5/0.

SIGSEGV: associated with the event "Segment Violation". Is generated
when the process tries to access an illegal memory segment (this is a
common error with pointers).

SIGINT: This is generated by the terminal (console) when the terminals
interrupt key (usually Ctrl+C) is pressed.

Every signal has an associated default action, that takes place when
the signal is generated. But this can be changed using one of the
signal functions (like signal(), sigaction()). These functions allow
us to specify a user defined action (function) for handling a signal.
Now after installing our own handler, if the signal occurs.. This time
the user specified action will be taken to handle that signal.

However there are some signals which cannot be caught and handled...
Like: SIGKILL, SIGSTOP.

Plzz refer to ur systems manual for more information...

- Gana


Signals provide a way to handle asynchronous (and unexpected) events.
A signal (number) is associated with an event. Like:

SIGFPE: associated with the event "Floating Point Error (FPE)". For
example: This occurs when the process tries to divide a number by zero
as in p=5/0.



Thank you so much for replying. Can you give me a code example that shows
how one may be able to use the signals in <signal.h> to handle asynchronous
(and unexpected) events? Should I call this function: "int raise(int sig)"?
I very much like to know how to use signals in a c code since the signals
are mentioned in the standard library.


"Jackie" <ja**********@earthlink.net> wrote in message news:<to***************@newsread2.news.pas.earthli nk.net>...

Thank you so much for replying. Can you give me a code example that shows
how one may be able to use the signals in <signal.h> to handle asynchronous
(and unexpected) events? Should I call this function: "int raise(int sig)"?
I very much like to know how to use signals in a c code since the signals
are mentioned in the standard library.



That confuses me a lot too. Even the function prototype
takes a while to figure out.

Let us see now.

void (*signal(int sig, void (*func)(int)))(int);

singal is a function taking two parameters and teturning
a pointer to a function.

The paramters are (1) an int, and (2) a pointer to a
function taking an int and returning nothing.

The return value is a pointer to a function taking an int
and returning nothing.

Does this seem ok?

Now, how do I declare a pointer to this signal function?


这篇关于&LT; signal.h中&GT; - 关于信号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆