Receiving a Signal and RealTime Signal - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Receiving a Signal and RealTime Signal

Description:

Two main purposes of signal: -making a process aware that a specific event has occurred ... terminates by resetting the segmentation registers saved on the Kernel Mode ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 21
Provided by: Susu152
Category:

less

Transcript and Presenter's Notes

Title: Receiving a Signal and RealTime Signal


1
Receiving a Signaland Real-Time Signal
  • prepared by He, Xiaosu

2
Contents
  • Remembering Signal
  • roles of signal
  • pending signal
  • performed actions of signal
  • Receiving Signal
  • do_signal ( ) function
  • system calls related to signal handling
  • Real Time Signal

3
Remembering Signal
  • Two main purposes of signal
  • -making a process aware that a specific event
    has occurred
  • -forcing a process to execute a signal
    handler function
  • included in its code
  • Pending signal
  • -signals that have been sent but not yet
    received
  • Three ways in which a process can respond
  • -explicitly ignore the signal
  • -execute the default action associated with
    the signal
  • -catch the signal by invoking a
    corresponding signalhandler
  • function

4
Receiving Signal
  • One phase related to signal transmission
  • three ways in which the kernel forces the
    destination process to react to the signal
  • by changing its execution state
  • by starting the execution of a specified
    signal handler
  • or both
  • Notice
  • signals are consumable resources
  • each signal sent received no more than once

5
do_signal ( ) function
  • Motive
  • in order to handle the nonblocked pending
    signals
  • Two parameters
  • -regs address of the stack area with User
    Mode
  • register contents of the current
    process
  • -oldset address of a variable with the bit
    mask
  • array of blocked signals (
    Null, when
  • invoked from ret_from_intr( ) )

6
do_signal ( ) function
  • Starting by checking
  • whether the interrupt occurred while the
    process was run-
  • ning in User Mode
  • dequeue_signal ( )
  • -heart of the do_signal ( ) function
  • -repeated invoking of dequeue_signal ( )
    until no more nonblocked pending signal
  • -its return code ( stored in the signr local
    variable )
  • value 0 -- all pending signals have
    been handled
  • value ! 0 -- a pending signal is
    waiting to be handled

7
do_signal ( ) function
  • notify_parent ( ) and schedule ( )
  • -when the current receiver process is being
    monitored by
  • some other process.
  • -to make the monitoring process aware of the
    signal handling
  • Loading the ka local variable
  • -with the address of the k_sigaction data
    structure
  • -perform three kinds of actions depending on
    the contents
  • ignoring the signal
  • executing a default action
  • executing a signal handler

8
Three Kinds of Actions
  • do_signal ( )
  • Ignoring the signal
  • No
    Yes
  • Executing the
  • default action
  • No Yes
  • Executing the
  • signal handler

9
Executing a Default Action
  • Depending on the signal type
  • -abort the process is destroyed
  • -dump the process is destroyed and a core
    file is created
  • -ignore the signal is ignored
  • -stop the process is stopped, put in a
    TASK_STOPPED state
  • -continue if the process is stopped
    (TASK_STOPPED), it is put into the TASK_RUNNING
    state

10
Catching the Signal
  • User Mode Kernel
    Mode

Normal program flow Signal
handler
return code on the stack
do_signal ( ) handle_signal ( )
setup_frame ( ) system_call ( )
sys_sigreturn ( )
restore_sigcontext ( )
11
Setting up the Frame
  • setup_frame ( )
  • -four parameters
  • sig -- signal number
  • ka -- address of the k_sigaction
    table associates with the signal
  • oldset -- address of a bit mask array
    of blocked signals
  • regs -- address in the Kernel Mode
    stack area where the User
  • Mode register contents
    have been saved
  • -a frame
  • data structure pushed onto the User
    Mode stack by this function
  • contains the information needed to
    handle the signal and to
  • ensure the correct return to the
    sys_sigreturn ( ) function
  • a sigframe table

12
Setting up the Frame
  • setup_frame ( ) function
  • -starts by invoking get_sigframe ( ) to
    compute the first memory location of the frame
  • -the returned address is verified by means of
    the access_ok macro
  • if valid -- the function repeatedly
    invokes __put_user ( ) to fill all
  • the fields of the
    frame
  • -modifies the regs area of the Kernel Mode
    stack
  • -terminates by resetting the segmentation
    registers saved on the Kernel Mode stack to their
    default value
  • setup_rt_frame ( ) function
  • an extended frame ( stored in the rt_sigframe
    data
  • structure ) on the User Mode stack

13
System Calls related to Signal Handling
  • The kill ( ) system call to send signals
  • kill ( pid, sig )
  • sys_kill ( ) ( service routine of kill ( ) )

  • send_sig_info ( )
  • kill_something_info ( )

  • kill_pg_info ( )


  • send_sig_info ( )
  • -meanings of pid parameter due to its
    numerical value

14
System Calls related to Signal Handling
  • The sigaction ( ) system call to specify an
    action for a signal
  • sigaction ( sig, act, oact)
  • sys_sigaction ( ) ( service routine of
    sigaction ( ) )
  • do_sigaction ( )
  • -three parameters
  • -pay attention to the sys_sigaction ( )
    function

15
System Calls related to Signal Handling
  • Other system calls
  • -sigpending ( )
  • allows a process to examine the set of pending
    blocked signals
  • applies only the standard signals
  • the corresponding service routine sys_sigpending
    ( ) acts on a single parameter set
  • -sigprocmask ( )
  • allows processes to modify the set of blocked
    signals
  • applies only the standard signals
  • the corresponding service routine sys_sigprocmask
    ( )
  • acts on three parameters oset, set, how

16
System Calls related to Signal handling
  • -sigsuspend ( )
  • suspends the process
  • the process will wake up only when a nonignored,
  • nonblocked signal is sent to it.
  • the corresponding service routine sys_sigsuspend
    ( )
  • sys_sigsuspend ( ) invokes the do_signal ( )
    function to
  • receive the signal that has woken up the
    process, when
  • the process that issued the sigsuspend ( )
    system call is
  • executed again.

17
Real Time Signals
  • Signal numbers 32-63
  • Difference with respect to standard signals
  • real-time signals of the same kind may be
    queued to ensure that multiple signals sent will
    be received
  • Linux kernel doesnt use real-time signals
  • the queue of real-time signals
  • a list of signal_queue elements

18
Real Time Signals
  • Process discriptor
  • has two specific fields
  • sigqueue points to the first element
    of the queue
  • sigqueue_tail points to the next
    field of the last
  • element of
    the queue
  • Sending
  • send_sig_info ( ) No. gt 31 ? inserts the
    signal in the queue
  • Receiving
  • dequeue_signal ( ) No. gt 31 ? extracts the
    element from the

  • queue

19
Real Time Signals
  • System Calls for Real-Time Signals
  • rt_sigaction ( )
  • rt_sigpending ( )
  • rt_sigprocmask ( )
  • rt_sigsuspend ( )
  • rt_sigqueueinfo ( )
  • sends a real-time signal to add to the
    real-time signal queue
  • destination process
  • rt_sigtimedwait ( )
  • the process remains suspended only for a
    fixed time interval

similar to those used for standard signals
20
Question
?
Write a Comment
User Comments (0)
About PowerShow.com