Suppress a background message in Bash

I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance that's running. I've seen a lot of suggestions to answer this here but either I'm not doing it right, or they're all wrong.

Here's the problematic part of the code:

control_c()
{
   echo -e "Would you like to do something?\n"
   echo -e "Enter y or n: "
   read yn

    if [ "$yn" == "y" ]; then

      echo -e "\nDoing something...\n"
      

                if [ -n $sumvar ]; then

                        echo -e "\nDoing Something else...\n"
                                bash what.sh
                        else
                                bash what.sh
                        fi
                fi


    else
          exit 0
    fi
}

trap control_c SIGINT
trap "rm -f /var/run/mine.pid" EXIT

pid=/var/run/mine.pid

if test -e $pid
then
        kilt=$(awk 'NR==1' $pid)
        exec kill -15 $kilt 2> /dev/null
else
        echo $$ > $pid
fi

Any help much appreciated!

What, exactly, are you trying to do? :confused: Not your code, your ultimate goal.

Well, I've written a very basic IDS. Sorry for not posting the code in its entirety, but its over 200 lines. It might be a lot to sort through and I really don't want to show it until its finished away. This is the last part I'm on.

Any help would be much appreciated.

Yes -- but what, exactly, are you trying to do?

Trying to get the "Terminated" message to not display. Even though the new instance of the script keeps running, a message will pop up saying "Terminated" (caused by killing the old instance's pid) and then a new command prompt. If you wait a second the new instance will give more output, but I don't want it to look to the user that the script has crashed. That's basically all.

Yes -- but what, exactly, are you trying to do?

Not one little short-term goal.

Not whatever manner you feel hellbent on accomplishing it with.

I only mean what, you are trying, to do. What function this script is supposed to accomplish. WHY you are killing processes in such a manner. Why you think this "prevents forking".

Until you explain that, your script isn't going to make much sense. I'm not sure it ever will -- it may need replacing, not minor fixes.

Also, please stop PMing me.

Don't know how explain it much better than the title of this thread. That's what I was trying to do. Make the message stop happening. With that the script would work and look fine. Sorry, I thought my explanations would make things clearer.

Because when it forks it kills one of the 2 current processes. If you know a better way than this or using exec, by all means show me.

Sorry, I could see I was having trouble explaining this to you. I thought sending you the entire code would let you see what I was talking about. It won't happen again.

The message should disappear when you trap signal 15 (that is SIGTERM on my systems).
But I second Corona that your code might need some redesign...