⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signal.3

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 3
字号:
.\" SCCSID: @(#)signal.3	2.1	3/10/87.TH signal 3 RISC.SH Namesignal \- simplified software signal facilities.SH Syntax.nf.B #include <signal.h>.PP.B (*signal(sig, func))().B void (*func)();.fi.SH Description.NXR "signal subroutine (standard C)".NXR "signal" "changing action".NXA "sigvec system call" "signal subroutine (standard C)"The.PN signalsubroutineis a simplified interface to the more general sigvec(2)facility..PPA signalis generated by some abnormal event,initiated by a user at a terminal (quit, interrupt, stop),by a program error (bus error, etc.),by request of another program (kill),or when a process is stopped because it wishes to accessits control terminal while in the background.  For furtherinformation, see .MS tty 4 .Signals are optionally generatedwhen a process resumes after being stopped,when the status of child process changes,or when input is ready at the control terminal.Most signals cause termination of the receiving process if no actionis taken; some signals instead cause the process receiving themto be stopped, or are simply discarded if the process has notrequested otherwise.Except for the SIGKILL and SIGSTOPsignals, the.PN signalcall allows signals either to be ignoredor to cause an interrupt to a specified location.The following is a list of all signals withnames as in the include file .br< signal.h >:.PP.NXR "signal subroutine (standard C)" "signal list".nf.ta \w'SIGVTALRM 'u +\w'15*  'uSIGHUP	1	HangupSIGINT	2	InterruptSIGQUIT	3*	QuitSIGILL	4*	Illegal instructionSIGTRAP	5*	Trace trapSIGIOT	6*	IOT instructionSIGEMT	7*	EMT instructionSIGFPE	8*	Floating point exceptionSIGKILL	9	Kill (cannot be caught or ignored)SIGBUS	10*	Bus errorSIGSEGV	11*	Segmentation violationSIGSYS	12*	Bad argument to system callSIGPIPE	13	write on a pipe with no one to read itSIGALRM	14	Alarm clockSIGTERM	15	Software termination signalSIGURG	16\(bu	Urgent condition present on socketSIGSTOP	17+	Stop (cannot be caught or ignored)SIGTSTP	18+	Stop signal generated from keyboardSIGCONT	19\(bu	Continue after stopSIGCHLD	20\(bu	Child status has changedSIGTTIN	21+	Background read attempted from control terminalSIGTTOU	22+	Background write attempted to control terminalSIGIO	23\(bu	I/O is possible on a descriptor (see fcntl(2))SIGXCPU	24	Cpu time limit exceeded (see setrlimit(2))SIGXFSZ	25	File size limit exceeded (see setrlimit(2))SIGVTALRM	26	Virtual time alarm (see setitimer(2))SIGPROF	27	Profiling timer alarm (see setitimer(2))SIGWINCH	28\(bu	Window size changeSIGLOST	29	lock not reclaimed after server recoverySIGUSR1	30	User defined signalSIGUSR2	31	User defined signalSIGCLD		System V name for SIGCHLDSIGABRT		X/OPEN name for SIGIOT.fi.PPThe starred signals in the list above cause a core imageif not caught or ignored..PPIf.I funcis SIG_DFL, the default actionfor signal.I sigis reinstated; this default is termination(with a core image for starred signals)except for signals marked with \(bu or +.Signals marked with \(bu are discarded if the actionis SIG_DFL; signals markedwith + cause the process to stop.If.I funcis SIG_IGN the signal is subsequently ignoredand pending instances of the signal are discarded.Otherwise, when the signal occursfurther occurrences of the signal areautomatically blocked and.I funcis called..PPA return from the function unblocksthe handled signal andcontinues the process at the point it was interrupted.Unlike previous signal facilities, the handler \fIfunc\fPremains installed after a signal has been delivered..PPIf a caught signal occursduring certain system calls, causingthe call to terminate prematurely, the callis automatically restarted.In particular this can occurduring a.I reador .MS write 2on a slow device (such as a terminal; but not a file)and during a .MS wait 2 ..PPThe value of.PN signalis the previous (or initial)value of.I funcfor the particular signal..PPAfter a .MS fork 2or .MS vfork 2the child inheritsall signals.The.MS execve 2system callresets all caught signals to the default action;ignored signals remain ignored..SH EnvironmentWhen your program is compiled using the System V environment the handlerfunction does NOT remain installed after the signal has been delivered..PPAlso, when a signal which is to be caught occurs during aread,  write, or ioctl to a slow device (likea terminal, but not a file); or during a  pause;  orwait that does not return immediately,  the  signal  handler  function is executed,and then the interrupted  system  call  mayreturn  a -1 to the calling process with errno setto EINTR..SH Notes The handler routine can be declared as follows:.PP    \f(CWhandler(sig, code, scp)    int sig, code;    struct sigcontext *scp;\fR.PPHere.I sigis the signal number.The MIPS hardware exceptions are mapped to specific signals as defined bythe table below.The parameter.I codeis either a constant as given below or zero.The parameter.I scpis a pointer to the.I sigcontextstructure (defined in.RI < signal.h >),that is the context at the time of the signal and isused to restore the context if the signal handler returns..PPThe following defines the mapping of MIPS hardware exceptions to signalsand codes.  All of these symbols are defined in either.RI < signal.h >or.RI < mips/cpu.h >:.PP.ta \w'     User Single Step (used by debuggers)   'u +\w'15*  'u +8n.nfHardware exception	Signal	Code.sp +.5Integer overflow	SIGFPE	EXC_OVSegmentation violation	SIGSEGV	SEXC_SEGVIllegal Instruction	SIGILL	EXC_IICoprocessor Unusable	SIGILL	SEXC_CPUData Bus Error	SIGBUS	EXC_DBEInstruction Bus Error	SIGBUS	EXC_IBERead Address Error	SIGBUS	EXC_RADEWrite Address Error	SIGBUS	EXC_WADEUser Breakpoint (used by debuggers)	SIGTRAP	BRK_USERBPKernel Breakpoint (used by prom)	SIGTRAP	BRK_KERNELBPTaken Branch Delay Emulation 	SIGTRAP	BRK_BD_TAKENNot Taken Branch Delay Emulation	SIGTRAP	BRK_BD_NOTTAKENUser Single Step (used by debuggers)	SIGTRAP	BRK_SSTEPBPOverflow Check	SIGTRAP	BRK_OVERFLOWDivide by Zero Check	SIGTRAP	BRK_DIVZERORange Error Check	SIGTRAP	BRK_RANGE.fi.PPWhen a signal handler is reached, the program counter in the signal contextstructure.RI ( sc_pc )points at the instruction that caused the exception as modified by the.I "branch delay"bit in the.I causeregister.The.I causeregister at the time of the exception is also saved in the sigcontextstructure.RI ( sc_cause ).If the instruction that caused the exception is at a valid user address itcan be retrieved with the following code sequence:.PP    \f(CWif(scp->sc_cause & CAUSE_BD){        branch_instruction = *(unsigned long *)(scp->sc_pc);        exception_instruction = *(unsigned long *)(scp->sc_pc + 4);    }    else        exception_instruction = *(unsigned long *)(scp->sc_pc);\fR.PPWhere CAUSE_BD is defined in.RI < mips/cpu.h >..PPThe signal handler may fix the cause of the exception and re-execute theinstruction, emulate the instruction and then step over it or perform somenon-local goto such as a.I longjump()or an.I exit()..PPIf corrective action is performed in the signal handler and the instructionthat caused the exception would then execute without a further exception, thesignal handler simply returns and re-executes the instruction (even when the.I "branch delay"bit is set)..PPIf execution is to continue after stepping over the instruction that caused theexception the program counter must be advanced.  If the.I "branch delay"bit is set the program counter is set to the target of the branch else it isincremented by 4..PPThis can be done with the following code sequence:.PP    \f(CWif(scp->sc_cause & CAUSE_BD)        emulate_branch(scp, branch_instruction);    else        scp->sc_pc += 4;\fR.PP.I Emulate_branch()modifies the program counter value in the sigcontext structure to the targetof the branch instruction.  See.I emulate_branch(3)for more details..PPFor SIGFPE's generated by floating-point instructions.RI ( code== 0) the.I "floating-point control and status"register at the time of the exception is also saved in the sigcontext structure.RI ( sc_fpc_csr ).This register has the information on which exceptions have occurred.When a signal handler is entered the register contains the value at the timeof the exception but with the.I "exceptions bits"cleared.On a return from the signal handler the exception bitsin the floating-point control and status register are also cleared sothat another SIGFPE does not occur (all other bits are restored from.IR sc_fpc_csr )..PPFor SIGSEGV and SIGBUS errors the faulting virtual address is saved in.I sc_badvaddrin the signal context structure..PPThe SIGTRAP's caused by.B breakinstructions noted in the above table and all other yet to be defined.B breakinstructions fill the.I codeparameter with the first argument to the.B breakinstruction (bits 25-16 of the instruction)..SH Return Values.NXR "signal subroutine (standard C)" "return value"The previous action is returned on a successful call.Otherwise, \-1 is returned and .I errnois set to indicate the error..SH DiagnosticsThe.PN signalsubroutine fails and action is not taken if one of the following occurs:.TP 15[EINVAL]The.I sigis not a valid signal number..TP 15[EINVAL]An attempt is made to ignore or supply a handler for SIGKILLor SIGSTOP..SH See Alsokill(1), kill(2), ptrace(2), sigblock(2), sigpause(2),sigsetmask(2), sigstack(2), sigvec(2), setjmp(3), tty(4)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -