Killing a process in a script

I use weird behavior for a specific application that I use. If I run the command in the background in bash, I can kill it using

$ command &
$ kill -n 2 [PID of command]
  killing command gracefully

However, when I throw this into the script:

command &
ID=$!
kill -n 2 $ID

he does not do anything. Are there any subtle flaws?

Edit: Another hint is that after the script terminates, I cannot kill the command using kill -n 2.

+3
source share
7 answers

human signal 7 You send signal 2, INT, to your process, that is, a keyboard interrupt, why? People say send signal 1, why?

The standard nifty way to kill a process is signal 15, the Termination Alarm, which is kill by default.

kill "$ PID"

, , , , "- $PID" "$ PID", , , "$ PID" , , , :

kill -15 -"$PID"

, kill -9 - "$ PID"

man 7 signal
man kill
+1

, bash SIGSTOP, SIGINT, .

0

ID $ , , , - PID. , :

 ID=`pidof -s command`
 kill -9 $ID
0

, , , -n - kill bash. -NAME , .

0

, , . set -m .

0

wait kill.

0

, script, / . , SIGKILL (1) :

kill -n 1 $ID
0

Source: https://habr.com/ru/post/1778001/


All Articles