Send Multiple Kill Signals to a Process

Send Multiple Kill Signals to a Process

Say I run a .sh process. And now I open a new terminal tab and I want to send signals to it, for that, I just use kill:

kill -*signal number* *pid*

right? But I want to send 13 signals at the same time, how can I do that?

2

1 Answer

You cannot send 13 signals at once but must loop over some list of signals. The following script will do so:

#!/usr/bin/env bash

pid=${1-""}

if [ -z "$pid" ]; then
    echo "a pid must be given";
    exit 1;
fi

siglist=(
    SIGSTOP SIGCONT SIGSTOP SIGCONT SIGSTOP SIGCONT
    SIGSTOP SIGCONT SIGSTOP SIGCONT SIGSTOP SIGCONT
    SIGTERM
)

for sig in "${siglist[@]}"; do
    kill -$sig $pid;
done

exit 0;

Save the script as send-sigs.sh, apply chmod +x send-sigs.sh and then call it like so:

./send-sigs.sh 1234

I used the signals STOP and CONT to alternately freeze and thaw the given pid but you can use different signals to your liking. But be aware that some signals might stop your target process so it won't receive any signals afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.