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 9196751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:09+00:00 2026-06-17T21:55:09+00:00

I have a bash script that calls a few rake tasks in succession. This

  • 0

I have a bash script that calls a few rake tasks in succession. This script is called by a continuous integration server. The problem is that if the integration server kills the task (by sending the script a SIGTERM), I can’t get the entire process tree to get killed. For instance, if Rake is running a set of rspec tests using the Parallel feature, the script and top level rake command can be killed, but inevitably some threads continue.

So far, I’ve tried many different ways of using the ‘trap’ command inside the bash script. I’ve tried finding all subprocess with pstree, using “kill -9 0” to kill the current process group, etc. If the script is killed while a rake tasks is running, however, it seems to bypass the trap. As far as I can tell Rake, or perhaps Ruby’s threading library, does something odd to the process group or possibly interferes with the trap.

If the script is not in the middle of a rake task, it will trap the SIGTERM correctly, echo “Received SIGTERM”, then kill all descendants.

How is it possible for Rake to interfere with a trap statement in the parent process (bash 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-17T21:55:10+00:00Added an answer on June 17, 2026 at 9:55 pm

    Bash assumes that the entire process group received the signal, so it will wait for the currently executing command to finish to determine what to do (more info). The trap will not run until the command has finished.

    If you don’t want to wait for the command to finish, you can instead use

    trap 'kill $!' TERM
    job &
    wait $!
    

    wait will exit immediately when the shell receives SIGTERM, causing your trap to run at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Bash script that calls another Bash script. The called script does
I have a bash script that simply calls different calls and redirect stdout and
I have a bash script that has this function in it: function start_vi() {
I have a bash script that looks like this: #!/bin/sh previousRelease=`git describe --tags --match
I have some problems with a PHP script that calls a Bash script.... in
I have a bash script that calls a java class method. The method returns
Problem: There is a C application that calls a Bash script each time an
I have a script that calls a subscript and attempts to release/disown this script
I have a bash script that calls a program which generates a humongous amount
I would like to do following: I have a bash script that calls an

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.