Listing 2 shows one way to register a signal handler.
清单2给出了一种注册信号处理程序的方法。
Suppose that the signal handler USES gethostbyname, which is non-reentrant.
假定信号处理器使用了不可重入的gethostbyname。
The code in Listing 8 implements a signal handler to deal with the incoming SIGCHLD signal.
清单8中的代码实现了一个处理传入的SIGCHLD信号的信号处理程序。
The process then continues executing, but the instructions in the signal handler are now executed.
然后进程继续执行,但现在执行的是信号处理器中的指令。
This example shows what can happen if a signal handler runs in the middle of modifying a variable.
这个例子展示了在修改某个变量的过程中运行信号处理器可能会发生什么事情?
Saving and restoring the value of errno in the signal handler, as follows, can resolve the problem
如下,在信号处理器内保存和恢复errno的值,可以解决这一问题
Now, in the signal handler you can't tell what the process was executing when the signal was caught.
现在,在信号处理器中您并不知道信号被捕获时进程正在执行什么内容。
The first way is to install a signal handler for the SIGBUS signal, and then simply call return in the handler.
第一种方式是为SIGBUS信号设置信号处理程序,并在处理程序中简单的执行return语句。
The only thing you should normally do inside a signal handler is set a global flag that will be processed later.
在一个信号处理器内部,您通常应该做的一件事是,设置一个将在以后处理的全局标记。
Note that condition functions are not asynchronously signal-safe and should not be called from a signal handler.
注意,条件函数并不是异步信号安全的,因此不能在信号处理函数中调用。
The best way to avoid the need to allocate memory in a handler is to allocate, in advance, space for signal handlers to use.
避免在处理器分配内存的最好方法是,为信号处理器预先分配要使用的内存。
But you're better off setting flags — and nothing else — in a signal handler, as opposed to trying to create sophisticated handlers.
但是您最好只在一个信号处理器中设置标记(别的什么都不做),这胜过尝试创建复杂的处理器。
The signal handler is called with a value of 18 (SIGCHLD), the child's exit is acknowledged, and the parent goes back to its sleep (60).
然后使用值18 (SIGCHLD)来调用信号处理程序,确认子进程的退出,并且父进程返回到sleep (60)。
What if the process was in the middle of allocating additional memory on its heap using malloc, and you call malloc from the signal handler?
如果当进程正在使用malloc在它的堆上分配额外的内存时,您通过信号处理器调用 malloc,那会怎样?
If the signal handler returns, the process continues executing the normal sequence of instructions it was executing when the signal was caught.
如果信号处理器返回,则进程继续执行信号被捕获时正在执行的正常的指令序列。
EINTR — the function was interrupted by a signal, which was caught by a signal handler in the program, and the signal handler returned normally.
程序中的信号处理程序捕获到函数的执行被某个信号中断,信号处理程序然后按正常方式返回。
When the signal handler doesn't disable, the process might show up in the "current" status as signal handling, which might hide the real problem.
未禁用信号处理程序时,进程在“当前”状态中可能表现为正在进行信号处理,从而可能隐藏了真正问题。
Listing 8 is slightly more complex than the previous example because of the sigset function, which assigns a function pointer to a signal handler.
由于使用了sigset函数(它向信号处理程序分配一个函数指针),清单8比前一个示例稍微复杂一点,。
Normally, the signal handler will return and cause the ioctl to be entered at exactly the point where it was left so the SPU program can continue.
通常,信号处理程序将会返回,并进入上次离开时ioctl的位置处,这样SPU程序就可以继续执行了。
Or, you call some function that was in the middle of the manipulation of the global data structure and you call the same function from the signal handler.
或者,调用了正在处理全局数据结构的某个函数,而在信号处理器中又调用了同一个函数。
Suppose the signal handler prints a message with fprintf and the program was in the middle of an fprintf call using the same stream when the signal was delivered.
假定信号处理器使用fprintf打印一条消息,而当信号发出时程序正在使用同一个流进行fprintf调用。
When a signal that is being caught is handled by a process, the normal sequence of instructions being executed by the process is temporarily interrupted by the signal handler.
当进程处理所捕获的信号时,正在执行的正常指令序列就会被信号处理器临时中断。
The SIGNAL statement is used to explicitly raise an error and force the invocation of a handler.
signal语句用于显式地发出一个错误并强制调用处理程序。
In other words, the instruction processed by the control unit after dealing with the interrupt signal is the first instruction of the selected handler.
换句话说,控制单元在解决完中断信号后,处理的指令就是选中的处理函数的第一条指令。
Commands are not added until the dog will perform the exercise 8 out of 10 times that the handler gives a signal.
在训练员发出信号后,狗儿能够按要求作出动作8到10次,才会加入口令。
If a handler wants his dog to go to his rug and points at the rug from behind the dog, that's a signal.
如果训练者站在狗的后面指着小毯子,想让狗到小毯子上去,这是手势。
If a handler wants his dog to go to his rug and points at the rug from behind the dog, that's a signal.
如果训练者站在狗的后面指着小毯子,想让狗到小毯子上去,这是手势。
应用推荐