Ping hbroomhall

Discussion in 'Linux / Unix Discussion' started by ffreeloader, Nov 29, 2005.

  1. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    I have a question for you. As you've done development on Linux projects, or at least have a lot of exposure to *nix and shells I would suspect the following is something you most likely know.

    Can you point me to a explanation for the different signals that the bash "kill" command sends? It functions somewhat differently than the system "kill" command does and for the life of me I can't find anything that explains just what the function of each of the signals does. I can find plenty of places that tell me just what the signals are, but none that tell what they do.

    The reason I'm asking is because I have a script in which I'm trying to run a function in the background and then kill it in the script but every time I try to kill the "last background process" for which, as you know, the variable is $!. I keep getting a "process not found or doesn't exist" error when the script calls "kill $!".

    I've had it echo $! to make sure the variable isn't empty and it returns a value that changes every time the script runs so I know that part is working correctly.

    The script in question is Example 9.2 in the Advanced Bash Scripting Guide. I can completely rewrite the script using TMOUT and my rewrite functions perfectly, but so far I haven't been able to figure out how to make the example work and the sticking point has been in killing the function that runs in the background.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Have you looked at "man signal"? On my box (admitedly not Linux) if gives a short description of each of the signals. If you need further expansion I'll try and find references.
    In what way does the bash builtin differ from /bin/kill? I have always thought they were identical.
    Not read the guide before so I'll take a look. For the avoidance of doubt - this is the script named "timed-input.sh"?

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Assuming I have the right script (and I dug through the doc revision history and it doesn't seem to have moved about) then I cut'n'pasted the script to my FreeBSD box. It worked! :eek:

    I also tried it on another FreeBSD box with a more recent version of bash and it worked there also.

    Versions of bash tried: 2.02.1 and 2.05a.0
    Version of script tried: 3.7 (although there seem to be no substantial changes made to it for a long time).

    Perhaps check for typos? Otherwise I'm slighty at a loss as to why it doesn't work.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  4. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    OK. Yeah, I've both typed in the script and cut-and-pasted it and both fail to work on my box. I've tried it in bash versions 2.05 and 3.0 and it failed in both.

    Last time I had something like this happen I had an alias getting in the way, but I don't have any aliases set up right now at all.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  5. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Um - well - the only Linux system I have access to at the moment is Knoppix, but that is at home. I'll try again tonight when I get back.

    I've also found a machine (still FreeBSD unfortunately) that is running bash 3.00.0 - and the script worked there as well!

    To avoid a possible race condition, try with the timeout set to longer than 3 secs - like 10 secs. The 'sleep' command has some strange side effects if the value slept is small.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  6. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    OK. I figured it out.

    Well, at least I got it working anyway. There was a small if...then statement in my .bashrc and in the system wide /etc/bash.bashrc that calls /etc/bash_completion if it exists. That statement was commented out in both files. I removed the comments in my .bashrc and now the script works. So, there's something in /etc/bash_completion that is needed for interactive scripts to execute properly in Debian's implementation of the bash shell. I took a look at /etc/bash_completion but it's a very long script and I got lost long before I figured out what it is.

    Well, at least this one only took about a day to figure out. Last time I had a script that wouldn't work I spent several days figuring out what was going on and it was finally someone from the debian-user mailing list that figured out what was going on.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  7. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    bash_completion is the system that gives you filename completion, among other things.

    I don't install it, and have no .bashrc, so the environment is not the same as you have.

    I'm glad you got it working in the end!

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  8. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    LOL. Me too! It looks as if I'm finally starting to get enough of an overall picture of what's going on built in my head that I'm able to start making some educated guesses on what is in the blank spots.

    Once I knew you could run the script I knew it had to be my environment and that was enough of a clue to find the solution. It's a long, slow process for an old fart like me, but I'm getting there.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  9. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    hbroomhall,

    Just in reference to what I said in the beginning about the "kill" command. What follows comes from the man page for "kill".

    When I was Googling on this problem I ran across a bunch instances where the above quote was the clue to the solution to the "kill" command not working correctly in a script.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  10. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Interesting. The man page on FreeBSD says:

    On a quick look I couldn't see any differences.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.