Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:18:19+00:00 2026-05-29T17:18:19+00:00

When a signal is received, I can execute some commands using trap . Example:

  • 0

When a signal is received, I can execute some commands using trap. Example:

trap 'echo hello world' 1 2

If any of the signals specified is received, the hello world’ is displayed.

But how can I print/identify the received signal name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:18:21+00:00Added an answer on May 29, 2026 at 5:18 pm

    (If you only have the number of a signal and want the name, kill -l $SIGNAL_NUM prints the name of a signal; you can avoid that by using the signal names instead of numbers in your call to trap as below.)

    This answer says that there’s no way to access the signal name, but if you have a separate function for each signal that you trap, then you already know the signal name:

    trap 'echo trapped the HUP signal' HUP
    trap 'echo different trap for the INT signal' INT
    

    In many cases, that may be sufficient, but another answer on that same question uses that fact to provide a workaround to fake the behavior you want. It takes a function and a list of signals and sets a separate trap for each signal on that function called with the signal name, so internally it’s actually a separate function for each signal but it looks like a single trap on a single function that gets the signal name as an argument:

    Code:

    #!/bin/bash
    
    trap_with_arg() {
        func="$1" ; shift
        for sig ; do
            trap "$func $sig" "$sig"
        done
    }
    
    func_trap() {
        echo "Trapped: $1"
    }
    
    trap_with_arg func_trap INT TERM EXIT
    
    echo "Send signals to PID $$ and type [enter] when done."
    read # Wait so the script doesn't exit.
    

    If I run that, then I can send signals to the process and I get output like

    Trapped: INT
    Trapped: TERM
    Trapped: EXIT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running on the device: Program received signal: EXC_BAD_ACCESS. Debugger: #0 0x31e11158 in CALayerCollectLayers_
I keep getting a -> Program received signal: EXC_BAD_ACCESS. In the following code but
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
How to trap signal on ruby running on windows? I want to send signal/message
i am getting program received signal sigabrt on main.m - (IBAction)segmentControl:(id)sender { NSTimeInterval oneUnit=(60*60*24*3);
Can any one guide me with invalid objects created in Objective-C. I am working
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -177935456 (LWP 5483)] 0xf79ff2ca in
I'm getting the following error Program received signal: EXC_BAD_ACCESS. warning: check_safe_call: could not restore
so when i'm running my app using XCode and I can see that my
I'm getting this error: Program received signal SIGSEGV, Segmentation fault. 0x0000000000407265 in Quadtree::deeper (this=0x7fffffffe430,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.