DOC PREVIEW
UNO CSCI 8530 - Signals

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 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 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11CSCI 8530SignalsOverview, Generation and HandlingLast updated: 4/3/20082Signal ReviewA signal is the software equivalent of a hardware interrupt or fault.Signals 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), ora process-generated signal (e.g. kill)Signal generation, delivery, and handling are each separate activities, occur at three separate times, and require separate examination.3Types 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 some keyboard entry, like control-C).Other signals may have no predefined generating events (e.g. SIGUSR1).Most signals with associated generating events can still be used for arbitrary purposes (but carefully!).See the <signal.h> file for details on signals available in a particular system, including their names and numbers.4Signal Generation – Step 1Some signals are automatically generated when certain events occur. For example, arithmetic, invalid instruction and memory protection faults will all generate a predefined signal associated with the fault.Other signals may be generated to report events. For example, pressing control-C on 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.5Signal Delivery – Step 2Signals can only be delivered to a running process! If the process is blocked, it must moved to the ready state before it can be selected for execution so it can be delivered a signal report.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 thus be mapped to a single occurrence.The order in which signals are delivered if multiple signals are pending is usually system dependent.6Asynchronous DeliveryWhen a signal is delivered to a process, it immediately causes whatever it was doing to be temporarily suspended while the action registered for that signal is carried out (unless the signal is masked, discussed later).Upon normal completion of the action associated with the signal, process of the “interrupted” process is resumed, either with the very next instruction, or with the instruction that caused the fault that generated the interrupt.27Advantages of AsynchronySince signals are asynchronous, they 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.8Disadvantages 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.9Disadvantages 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.10Default ActionsIf a process has not prepared itself to process a particular signal, a default action is taken when that signal is delivered to the process.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.If, on the other hand, a process has specified what to do when a signal is delivered, then that action is taken instead of the default action.11Default Action PossibilitiesAbort – terminate the process after generating a dump (creation of a file containing a copy of the memory associated with the process, suitable for use with a debugger like gdb).Exit – terminate the process without generating a dumpIgnore – ignore the signal as if it had not occurredStop – suspend the process (e.g. don’t schedule it)Continue – resumes the process, if suspended12ObservationsIt 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.313Simple (ANSI) Signal HandlingThe simplest signal handling technique is to use the signalfunction:signal(SIGNAME,functionname);SIGNAME is the name (from <signal.h>) or 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.signal returns the previously registered functionname (that is, a pointer to a function) for the signal being registered.14Signal 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 –pididentifies a process group, each process of which is sent the signal.15ANSI 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.16The setjmp FunctionThe setjmp function is used to record its


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?