为什么信号存在? [英] Why do signals exist?

查看:56
本文介绍了为什么信号存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信号的目的是什么?为什么它们存在于C?

提前感谢

What is the purpose of signals and why do they exist in C?
thanks in advance

推荐答案

< a href =mailto:vi ****** @ gmail.com> vi ****** @ gmail.com 写道:

信号的目的是什么?为什么它们存在于C?

提前感谢
What is the purpose of signals and why do they exist in C?
thanks in advance



信号是C'的模型机制大多数操作环境

提供处理两种事件:错误或异常

由程序自己的行为引起的条件(例如,当

它除以零或取消引用NULL),以及来自程序外的
的干预(例如,按^ C来中断它)。一个

C程序可以设置信号处理程序,当这些异常或外部事件发生时,调用特殊函数

;处理程序

可以以适当的方式响应事件。


这些事件究竟是如何产生的详细信息,已发送,

和处理的处理方式因O / S而异,因此

C标准对于实际发生的事情几乎没有说明:它不是
列表所有可能的信号,它没有说哪些可以被忽略

哪个不能,它没有说明如果信号处理器

试图恢复会发生什么大多数信号后正常运行。从某种意义上说,标准的信号机制主要是存根,而不是存根。一个简单的

vanilla界面到一个领域,其细节大部分都在

标准本身之外。因此,在便携式C代码中没有很多你可以使用信号

,因为即使signal()函数是
a便携式接口,它与它接口的东西也是如此是不可移植的。

一个非常简单地使用信号的程序通常与特定操作系统的细节紧密相关。



-

Eric Sosman
es ** ***@ieee-dot-org.inva


vi ****** @ gmail.com 写道:
vi******@gmail.com wrote:

信号的目的是什么?为什么它们存在于C?

提前感谢
What is the purpose of signals and why do they exist in C?
thanks in advance



它们的存在是为了向

程序提供事件的异步通知。 C99标准定义了六种标准信号。实现

可以定义更多,几乎所有关于处理信号的内容都是定义的实现。 POSIX提供更丰富的信号支持和更多

的行为保证。


见标准7.14节。

They exist to provide asynchronous notification of events to the
program. The C99 Standard defines six standard signals. Implementations
may define more and almost everything about handling signals is
implementation defined. POSIX provides richer signal support and more
guarantees on behaviour.

See section 7.14 of the Standard.


1月28日晚上8点34分,Eric Sosman< esos ... @ ieee-dot-org.invalidwrote:
On Jan 28, 8:34 pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:

vipps ... @ gmail.com写道:
vipps...@gmail.com wrote:

信号的目的是什么?为什么它们存在于C?

提前感谢
What is the purpose of signals and why do they exist in C?
thanks in advance



信号是C'大多数操作环境机制的模型

提供处理两种事件:错误或异常
由程序自己的行为引起的条件(例如,

它除以零或取消引用NULL),以及来自

之外的干预程序(例如,按^ C来中断它)。一个

C程序可以设置信号处理程序,当这些异常或外部事件发生时,调用特殊函数

;处理程序

可以以适当的方式响应事件。


这些事件究竟是如何产生的详细信息,已发送,

和处理的处理方式因O / S而异,因此

C标准对于实际发生的事情几乎没有说明:它不是
列表所有可能的信号,它没有说哪些可以被忽略

哪个不能,它没有说明如果信号处理器

试图恢复会发生什么大多数信号后正常运行。从某种意义上说,标准的信号机制主要是存根,而不是存根。一个简单的

vanilla界面到一个领域,其细节大部分都在

标准本身之外。因此,在便携式C代码中没有很多你可以使用信号

,因为即使signal()函数是
a便携式接口,它与它接口的东西也是如此是不可移植的。

一个非常简单地使用信号的程序通常与特定操作系统的细节紧密相关。


Signals are C''s model of mechanisms most operating environments
provide to handle two kinds of events: erroneous or exceptional
conditions arising from a program''s own actions (for example, when
it divides by zero or dereferences NULL), and interventions from
outside the program (for example, hitting ^C to interrupt it). A
C program can set up "signal handlers," special functions that are
called when these exceptional or external events occur; the handler
can respond to the event in some appropriate way.

The details of exactly how these events arise, are dispatched,
and are processed vary greatly from one O/S to another, so the
C Standard says very little about what really goes on: It doesn''t
list all the possible signals, it doesn''t say which can be ignored
and which cannot, it doesn''t say what happens if a signal handler
tries to resume normal operation after most signals. In a sense,
the Standard''s mechanism for signals is mostly a "stub," a plain-
vanilla interface to a realm whose details are mostly outside the
Standard itself. Thus, there is not a lot you can do with signals
in portable C code, because even though the signal() function is
a portable interface, the thing it interfaces with is non-portable.
A program that makes non-trivial use of signals is usually tied
pretty tightly to the specifics of a particular O/S.



谢谢Sossman先生,但我仍然没有看到ISO C需要信号的原因。 $ $ $
我理解为什么像POSIX这样的标准需要它们,但我不会理解ISO决定将它们包含在标准C中。

我也认为你误解了我的问题,也许它很糟糕

措辞。

我知道是什么信号(作为编程中的概念)但我做了

不理解ISO C中信号背后的概念及其用途。

然后,也许是我误解了。


Thanks mr Sossman, but I still don''t see the reason why ISO C would
need signals.
I understand why a standard like POSIX would need them, but I don''t
understand ISOs decision to include them in standard C.
I also think you misunderstood my question, perhaps it was poorly
worded.
I do know what signals are for (as a concept in programming) but I did
not understand the concept behind signals in ISO C, and their use.
Then again, perhaps it was me who misunderstood.


这篇关于为什么信号存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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