Find the answer to your Linux question:
Results 1 to 3 of 3
I have a script that starts a subshell Code: #!/bin/sh local SSPID clean_exit() { #here the subshell shall be killed exit 0 } trap clean_exit INT TERM EXIT while true ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    2

    Howto terminate all running subshells?


    I have a script that starts a subshell

    Code:
    #!/bin/sh
    
    local SSPID
    
    clean_exit() {
      #here the subshell shall be killed
      exit 0
    }
    
    trap clean_exit INT TERM EXIT
    
    while true
    do
      #open a subshell that waits for events, let's say user input
      cmd=$(read)
      #do something with the $cmd
      ...
    done
    so the script waits in the loop for the subshell to finish then does processing and starts over. If I kill the script the subshell is not killed. So I can trap the TERM event and do some cleaning but I need to know the subshell process id.

    I'm using busybox so ps does not accept any parameters
    I cannot source subshell so it can access its parent environment

    So how can it done? Thanks

  2. #2
    Just Joined! barriehie's Avatar
    Join Date
    Apr 2008
    Location
    The Desert!
    Posts
    85
    So can you get the subshell to do something with $$, the PID?

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    2
    what should the subshell do with its parent PID?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •