user3302786
user3302786

Reputation: 29

SIGINT in bash script

I have the following bash script.

#!/bin/bash
while :
do
    sleep 2
    infiniteProgramm -someParametrs
    sleep 10
    #in this line I need to stop my infiniteProgramm with bash command (SIGINT) (like Ctrl+C, but automatic)
    clear
done

How can I send a SIGINT signal to my infiniteProgramm?

Upvotes: 1

Views: 2446

Answers (1)

choroba
choroba

Reputation: 241738

First: run infiniteProgram in the background:

infiniteProgram -someParameters &

Second: retrieve its PID from $!.

pid=$!

Third: kill it.

sleep 10
kill -2 $pid

2 corresponds to SIGINT, see kill -l for the list of all the signals.

Upvotes: 2

Related Questions