I\'m starting a number of screens in a bash script, then running django\'s runserver
command in each of them. I\'d like to be able to programmatically stop them
ctrl+c and kill -INT
are not exactly the same, to emulate ctrl+c we need to first understand the difference.
kill -INT
will send the INT
signal to a given process (found with its pid
).
ctrl+c is mapped to the intr
special character which when received by the terminal should send INT
to the foreground process group of that terminal. You can emulate that by targetting the group of your given
. It can be done by prepending a -
before the signal in the kill command. Hence the command you want is:
kill -INT -
You can test it pretty easily with a script:
#!/usr/bin/env ruby
fork {
trap(:INT) {
puts 'signal received in child!'
exit
}
sleep 1_000
}
puts "run `kill -INT -#{Process.pid}` in any other terminal window."
Process.wait
Sources: