DOC PREVIEW
UNO CSCI 8530 - Signals

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1CSCI 8530SignalsOverview, Generation and HandlingSignal ReviewA signal is the software equivalent of an interrupt or fault.They provide a way for a procedure to be called when one of a defined set of events occurs.Events may be a fault (e.g. division by zero), a user action (pressing control-C), or a process-generated signal (e.g. kill).Signal generation, delivery, and handling are each separate activities, occur at three separate times, and requiring separate examinations.2Types of SignalsEach system defines and supports some number of signals, identified by number (1, 2, …) and name. QNX, for example, supports 32 (non-real-time) signal types.Some signals are associated with their generating events (e.g. SIGINT, usually generated by a keyboard interrupt like control-C).Other signals may have no predefined generating events (e.g. SIGUSR1).Most signals with associated events can still be used for arbitrary purposes (but carefully!).(See <signal.h> for details on system signals.)Signal GenerationSome signals are automatically generated when certain events occur. For example, arithmetic, invalid instruction and memory protection faults will all generate an associated signal.Other signals may be generated to report events. For example, control-C at the keyboard, asynchronous I/O completion, and a timer’s expiration can each cause a signal to be generated.Finally, a process can use the kill and raisefunctions to explicitly generate signals.3Signal DeliverySignals can only be delivered to a running process!Most systems use a bit map to record which signals have occurred prior to their delivery. Multiple occurrences of the same signal prior to its delivery will be mapped to a single occurrence.The order in which signals are delivered if multiple signals are pending is usually system dependent.Advantages of AsynchronySignals are asynchronous, meaning a signal can be delivered to a process while it is doing something else.The advantages of this are:immediacy: you are notified immediately (for somevalue of immediately) when something occurs.concurrency: you can be off doing something else while other processing goes on concurrently with your application. When that other processing completes, you are notified via a signal.4Disadvantages of Asynchrony (1)Complexity: If your application must prepare for the possibility of a signal at any point in its execution, the application is going to become more complex. With complexity comes a lack of robustness, difficulty in understanding and maintaining, and so on.Non-determinism: You don’t really know when a signal is going to arrive, relative to other signals or even to the event that caused the signal to be delivered. Signal delivery happens “under the hood” of the operating system, and usually isn’t well documented.Disadvantages of Asynchrony (2)Lower performance: Signals are slower than the synchronous mechanisms for communication, because asynchrony costs. It takes time to stop an application, set up an appropriate environment in which to call the signal handler, and then actually call the handler. None of that overhead is required when one is just synchronously waiting for an occurrence.5Default ActionsIf a process has not prepared itself to receive a particular signal, a default action is taken.For most signals, this default action is to terminate the process (that is, abort or exit).For a few other signals, the default action is to ignore the signal.Default Actions (2)Abort – terminate the process after generating a dumpExit – terminate the process without generating a dumpIgnore – the signal is ignoredStop – suspends the processContinue – resumes the process, if suspended6ObservationsIt is important to note that any action, including process termination, can only be taken by the process receiving the signal.This requires, at the very least, that the process be scheduled to run.On a busy system, if the process has a low priority, this could take quite some time.There may be further delay if a process is swapped out, suspended, or blocked in an uninterruptible way.Simple (ANSI) Signal HandlingThe simplest signal handling technique is to use the signalfunction:signal(SIGNAME,functionname);SIGNAME is the name (from <signal.h>) or the number of a signal we wish to handle.functionname is the name (address) of the function that will be invoked when SIGNAME is delivered to the process; it may also be SIG_DFL or SIG_IGN (see next slide).signal returns the previously registered functionname (that is, a pointer to a function) for the signal being registered.7SIG_IGN and SIG_DFLSIG_IGN can be used in place of a function name for the signal system call. In this case, the signal will be ignored when it is delivered to the process. Note that the signal is still delivered, but no signal handler or default action is taken. Some signals, in particular SIGKILL and SIGSTOP, cannot be ignored.SIG_DFL can be used in place of a function name to restore the default signal handler for a particular signal.Signal Generation Functionsraise(signo) causes the specified signal to be sent to the process that executes the call to raise.kill(pid,signo) sends the specified signal to the specified process (pid). If pid is zero, then each process in the same group as the calling process is sent the signal. If pid is negative, then –pid identifies a process group, to each process of which the signal is sent.8Who can signal whom?Can any process send a signal to any other process?NO. For the “kill” system call to be effective (that is, be allowed), the sending process (the one executing “kill”) must be executing with root privileges (i.e. superuser) or it must have the same real or effective user ID as that of the process to which the signal is sent.ANSI Signal-handling FunctionsThe function named in the signal call is passed the (integer) number of the signal as its sole argument, and has a void return type.The function may eventuallyreturn, to resume execution at the point the program was interrupted;terminate using exit or abort; orcall the longjmp or siglongjmp function.9Returning to the interrupted codeWhen a signal handler returns (as opposed to exiting, aborting, or performing a [sig]longjmp), the interrupt code resumes execution.Depending on the architecture and the type of signal, execution resumes by reexecuting the instruction that caused the signal (e.g. a divide instruction that caused an overflow is reexecuted), or by


View Full Document

UNO CSCI 8530 - Signals

Download Signals
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Signals and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Signals 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?