hotshot has asked for the wisdom of the Perl Monks concerning the following question:

Hotshot I have a script that runs a shell I wrote. I want to be able to kill it from the same shell opened by another user but I want to send him a message before I kill him (so he'll know what happen), just using kill('KILL', $pid); writes 'killed' on his screen, this isn't enough for me. I tried sending him SIGPIPE, and catch it in his shell (and printing what I wanted) and then using 'exit' or 'die' there, this did the work but also wrecked the Unix shell (pressing 'enter' prints the prompt horizontally instead of vertically, the input I enters doesn't seems on screen, etc.) can someone help?

Replies are listed 'Best First'.
Re: killing a process
by MZSanford (Curate) on Nov 19, 2001 at 16:26 UTC
    The best i can suggest for writting to a terminal before killing, is to use with the unix write program , or even print directly into the users tty (though that not usually very nice, as if they are typing a command it will interrupt). Once that is done, you could kill the shell as normal. This works diffrent ways on diffrent systems, and on many the echo "foo" > /dev/tty2 trick does not work, so test it on yours.
    i had a memory leak once, and it ruined my favorite shirt.
      Hotshot
      I tried what you said, but as you mentioned, the solution you suggested works differntly on different systems, and I wasn't lucky here, so I tried sending SIGPIPE to the process and catch it there, in my sigPipe handler I printed a message to the user and comitted suicide with:
      kill('KILL', $$);
      and it worked perfectly
      but thanks anyway
Re: killing a process
by kjherron (Pilgrim) on Nov 19, 2001 at 20:38 UTC
    If I understand your description, the process you're killing is a program that your wrote? In this case, it seems to me that the best way to handle this is to have this program catch the signal that you're sending, print an appropriate message, and exit on its own. This will be much simpler and more reliable than some foreign process trying to write to the user's tty.