Unformatted text preview:

CSCI 8530 Signals Overview Generation and Handling Signal Review A 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 processgenerated signal e g kill Signal generation delivery and handling are each separate activities occur at three separate times and requiring separate examinations 1 Types of Signals Each 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 Generation Some 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 raise functions to explicitly generate signals 2 Signal Delivery Signals 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 Asynchrony Signals 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 some value 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 3 Disadvantages 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 4 Default Actions If 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 dump Exit terminate the process without generating a dump Ignore the signal is ignored Stop suspends the process Continue resumes the process if suspended 5 Observations It 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 Handling The simplest signal handling technique is to use the signal function signal SIGNAME functionname 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 SIGNAME 6 SIG IGN and SIG DFL SIG 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 Functions raise 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 7 Who 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 Functions The 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 eventually return to resume execution at the point the program was interrupted terminate using exit or abort or call the longjmp or siglongjmp function 8 Returning to the interrupted code When 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 continuing with the next instruction e g after a SIGINT signal generated by pressing control C was handled The setjmp Function The setjmp function is used to record its


View Full Document

UNO CSCI 8530 - Signals

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 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?