#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0

    Why do children of a shell script refuse to die?


    First of all, this is a Solaris question. I have a (bash) shell script abc.sh, which looks as follows:

    #!/bin/bash
    /some/perl/script.pl

    The perl script is designed to hang (not by me), by trying to suck some data out from a bad URL (the URL never gives any data back) and there is no timeout.

    Now, all I want to do is to be able to kill abc.sh with a single kill -9 without any residual processes hanging about afterwards. The problem is that the perl script refuses to die upon a kill -9 issued to the process of abc.sh.

    Before issuing a SIGKILL (kill -9) to the process of abc.sh, a ps -ef shows the parent of the hung perl process to be abc.sh. After issuing a SIGKILL, the parent becomes 1 (/etc/init, as far as I remember). A subsequent kill -9 to the perl process kills it without any problems.

    Can anyone think why the perl script would ignore the SIGKILL, which, AFAIK, gets passed through to it? If I am wrong in thinking that it gets passed to it, which is quite likely, then is there a way to pass it through nicely?

    My main problem is that killing the script abc.sh is the only thing I can do (I have to use Java's Process.destroy() on it), as normally, I would not have the pid of any of its children (again, as the result of using Java).

    Thanks,

    MT
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    11
    Nothing unusual about this. This is standard UNIX behavour.
    Why not invoke the Perl script directly without going through
    a shell?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0
    Originally Posted by fpmurphy
    Nothing unusual about this. This is standard UNIX behavour.
    Why not invoke the Perl script directly without going through
    a shell?
    True, it is standard unix behaviour. However, I cannot invoke the perl script directly (say, I need to invoke another one after it), so I must go through a script.

    Perhaps the question should sound as follows: is there a way to write a script in such a way that its children would die when it is killed?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Pacific NW, USA
    Posts
    26
    Rep Power
    0
    Maybe try using the trap command.

    Look up man for more info
  8. #5
  9. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Location
    Bangladesh
    Posts
    1
    Rep Power
    0

    stomatolog


    Account suspended

IMN logo majestic logo threadwatch logo seochat tools logo