📄 1.3.t
字号:
.\" Copyright (c) 1983, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)1.3.t 8.1 (Berkeley) 6/8/93.\".sh "Signals.PP.NH 3Overview.PPThe system defines a set of \fIsignals\fP that may be deliveredto a process. Signal delivery resembles the occurrence of a hardwareinterrupt: the signal is blocked from further occurrence,the current process context is saved, and a new oneis built. A process may specifythe \fIhandler\fP to which a signal is delivered, or specify thatthe signal is to be \fIblocked\fP or \fIignored\fP. A process mayalso specify that a\fIdefault\fP action is to be taken when signals occur..PPSome signalswill cause a process to exit when they are not caught. Thismay be accompanied by creation of a \fIcore\fP image file, containingthe current memory image of the process for use in post-mortem debugging.A process may choose to have signals delivered on a specialstack, so that sophisticated software stack manipulations are possible..PPAll signals have the same \fIpriority\fP. If multiple signalsare pending simultaneously, the order in which they are deliveredto a process is implementation specific. Signal routines executewith the signal that caused their invocation \fIblocked\fP, but othersignals may yet occur. Mechanisms are provided whereby critical sectionsof code may protect themselves against the occurrence of specified signals..NH 3Signal types.PPThe signals defined by the system fall into one offive classes: hardware conditions,software conditions, input/output notification, process control, orresource control.The set of signals is defined in the file \fI<signal.h>\fP..PPHardware signals are derived from exceptional conditions whichmay occur duringexecution. Such signals include SIGFPE representing floatingpoint and other arithmetic exceptions, SIGILL for illegal instructionexecution, SIGSEGV for addresses outside the currently assignedarea of memory, and SIGBUS for accesses that violate memoryprotection constraints.Other, more cpu-specific hardware signals exist,such as those for the various customer-reserved instructions onthe VAX (SIGIOT, SIGEMT, and SIGTRAP). .PPSoftware signals reflect interrupts generated by user request:SIGINT for the normal interrupt signal; SIGQUIT for the morepowerful \fIquit\fP signal, that normally causes a core imageto be generated; SIGHUP and SIGTERM that cause gracefulprocess termination, either because a user has ``hung up'', orby user or program request; and SIGKILL, a more powerful terminationsignal which a process cannot catch or ignore.Programs may define their own asynchronous events using SIGUSR1and SIGUSR2.Other software signals (SIGALRM, SIGVTALRM, SIGPROF)indicate the expiration of interval timers..PPA process can request notification via a SIGIO signalwhen input or output is possibleon a descriptor, or when a \fInon-blocking\fP operation completes.A process may request to receive a SIGURG signal when anurgent condition arises. .PPA process may be \fIstopped\fP by a signal sent to it or the membersof its process group. The SIGSTOP signal is a powerful stopsignal, because it cannot be caught. Other stop signalsSIGTSTP, SIGTTIN, and SIGTTOU are used when a user request, inputrequest, or output request respectively is the reason for stopping the process.A SIGCONT signal is sent to a process when it iscontinued from a stopped state.Processes may receive notification with a SIGCHLD signal whena child process changes state, either by stopping or by terminating..PPExceeding resource limits may cause signals to be generated.SIGXCPU occurs when a process nears its CPU time limit and SIGXFSZwarns that the limit on file size creation has been reached..NH 3Signal handlers.PPA process has a handler associated with each signal.The handler controls the way the signal is delivered.The call.DS#include <signal.h>._fstruct sigvec { int (*sv_handler)(); int sv_mask; int sv_flags;};sigvec(signo, sv, osv)int signo; struct sigvec *sv; result struct sigvec *osv;.DEassigns interrupt handler address \fIsv_handler\fP to signal \fIsigno\fP.Each handler addressspecifies either an interrupt routine for the signal, that thesignal is to be ignored,or that a default action (usually process termination) is to occurif the signal occurs.The constantsSIG_IGN and SIG_DEF used as values for \fIsv_handler\fPcause ignoring or defaulting of a condition.The \fIsv_mask\fP value specifies thesignal mask to be used when the handler is invoked; it implicitly includesthe signal which invoked the handler.Signal masks include one bit for each signal;the mask for a signal \fIsigno\fP is provided by the macro\fIsigmask\fP(\fIsigno\fP), from \fI<signal.h>\fP.\fISv_flags\fP specifies whether system calls should berestarted if the signal handler returns andwhether the handler should operate on the normal run-timestack or a special signal stack (see below). If \fIosv\fPis non-zero, the previous signal vector is returned..PPWhen a signal condition arises for a process, the signalis added to a set of signals pending for the process.If the signal is not currently \fIblocked\fP by the processthen it will be delivered. The process of signal deliveryadds the signal to be delivered and those signalsspecified in the associated signalhandler's \fIsv_mask\fP to a set of those \fImasked\fPfor the process, saves the current process context,and places the process in the context of the signalhandling routine. The call is arranged so that if the signalhandling routine exits normally the signal mask will be restoredand the process will resume execution in the original context.If the process wishes to resume in a different context, thenit must arrange to restore the signal mask itself..PPThe mask of \fIblocked\fP signals is independent of handlers forsignals. It delays signals from being delivered much as araised hardware interrupt priority level delays hardware interrupts.Preventing an interrupt from occurring by changing the handler is analogous todisabling a device from further interrupts..PPThe signal handling routine \fIsv_handler\fP is called by a C callof the form.DS(*sv_handler)(signo, code, scp);int signo; long code; struct sigcontext *scp;.DEThe \fIsigno\fP gives the number of the signal that occurred, andthe \fIcode\fP, a word of information supplied by the hardware.The \fIscp\fP parameter is a pointer to a machine-dependentstructure containing the information for restoring thecontext before the signal..NH 3Sending signals.PPA process can send a signal to another process or group of processeswith the calls:.DSkill(pid, signo)int pid, signo;killpgrp(pgrp, signo)int pgrp, signo;.DEUnless the process sending the signal is privileged,it must have the same effective user id as the process receiving the signal..PPSignals are also sent implicitly from a terminal device to theprocess group associated with the terminal when certain input charactersare typed..NH 3Protecting critical sections.PPTo block a section of code against one or more signals, a \fIsigblock\fPcall may be used to add a set of signals to the existing mask, returningthe old mask:.DSoldmask = sigblock(mask);result long oldmask; long mask;.DEThe old mask can then be restored later with \fIsigsetmask\fP\|,.DSoldmask = sigsetmask(mask);result long oldmask; long mask;.DEThe \fIsigblock\fP call can be used to read the current maskby specifying an empty \fImask\fP\|..PPIt is possible to check conditions with some signals blocked,and then to pause waiting for a signal and restoring the mask, by using:.DSsigpause(mask);long mask;.DE.NH 3Signal stacks.PPApplications that maintain complex or fixed size stacks can usethe call.DS._fstruct sigstack { caddr_t ss_sp; int ss_onstack;};sigstack(ss, oss)struct sigstack *ss; result struct sigstack *oss;.DEto provide the system with a stack based at \fIss_sp\fP for deliveryof signals. The value \fIss_onstack\fP indicates whether theprocess is currently on the signal stack,a notion maintained in software by the system..PPWhen a signal is to be delivered, the system checks whetherthe process is on a signal stack. If not, then the process is switchedto the signal stack for delivery, with the return from the signalarranged to restore the previous stack..PPIf the process wishes to take a non-local exit from the signal routine,or run code from the signal stack that uses a different stack,a \fIsigstack\fP call should be used to reset the signal stack.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -