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

  • Home
  • SEARCH
  • 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 9245169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:12:19+00:00 2026-06-18T09:12:19+00:00

Is there any way to invoke a subprocess so that it and all its

  • 0

Is there any way to invoke a subprocess so that it and all its descendants are sent an interrupt, just as if you Ctrl-C a foreground task? I’m trying to kill a launcher script that invokes a long-running child. I’ve tried kill -SIGINT $child (which doesn’t send the interrupt to its descendants so is a no-op) and kill -SIGINT -$child (which works when invoked interactively but not when running in a script).

Here’s a test script. The long-running script is test.sh --child. When you call test.sh --parent, it invokes test.sh --child & and then tries to kill it. How can I make the parent kill the child successfully?

#!/bin/bash

if [ "$1" = "--child" ]; then
sleep 1000

elif [ "$1" = "--parent" ]; then
"$0" --child &
for child in $(jobs -p); do
  echo kill -SIGINT "-$child" && kill -SIGINT "-$child"
done
wait $(jobs -p)

else
echo "Must be invoked with --child or --parent."
fi

I know that you can modify the long-running child to trap signals, send them to its subprocess, and then wait (from
Bash script kill background (grand)children on Ctrl+C), but is there any way without modifying the child script?

  • 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-06-18T09:12:20+00:00Added an answer on June 18, 2026 at 9:12 am

    Read this : How to send a signal SIGINT from script to script ? BASH

    Also from info bash

       To facilitate the implementation of the user interface to job  control,
       the operating system maintains the notion of a current terminal process
       group ID.  Members of this process group (processes whose process group
       ID is equal to the current terminal process group ID) receive keyboard-
       generated signals such as SIGINT.  These processes are said  to  be  in
       the  foreground.  Background processes are those whose process group ID
       differs from the terminal's; such processes are immune to keyboard-gen‐
       erated signals. 
    

    So bash differentiates background processes from foreground processes by the process group ID. If the process group id is equal to process id, then the process is a foreground process, and will terminate when it receives a SIGINT signal. Otherwise it will not terminate (unless it is trapped).

    You can see the process group Id with

    ps x -o  "%p %r %y %x %c "
    

    Thus, when you run a background process (with &) from within a script, it will ignore the SIGINT signal, unless it is trapped.

    However, you can still kill the child process with other signals, such as SIGKILL, SIGTERM, etc.

    For example, if you change your script to the following it will successfully kill the child process:

    #!/bin/bash
    
    if [ "$1" = "--child" ]; then
      sleep 1000
    elif [ "$1" = "--parent" ]; then
      "$0" --child &
      for child in $(jobs -p); do
        echo kill "$child" && kill "$child"
      done
      wait $(jobs -p)
    
      else
      echo "Must be invoked with --child or --parent."
    fi
    

    Output:

    $ ./test.sh --parent
    kill 2187
    ./test.sh: line 10:  2187 Terminated              "$0" --child
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to get the text of the selector that invoked some
Is there any way I can set a formatter on models that will convert
Is there any way how to invoke a PHP page / function when a
Is there any way to invoke a Java program for a particular URL in
Is there any way to invoke remote web beans( CDI ) in java EE
Is there any way to make Django's template loader run all templates it loads
Is there any way to determine if process was invoked by current application? I'm
Is there any way in Notepad++ (or even with another tool) to change the
Is there any way to use Google's API to retrieve a user's current zipcode
Is there any way to overload the > (greater than) operator, to be able

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.