我正在尝试在 linux ( ubuntu ) 上创建和终止进程组
我正在尝试杀死一个进程组,并且由于 pkill -P $ID 有效而 Kill -- -$ID 无效这一事实而让我发疯。在除此之外的情况下,此脚本 Kill ---$ID 按预期工作并杀死进程和子进程,但在这种情况下,它报告未找到进程,而 pkill -P 按预期杀死组。
为什么 pkill 有效而kill 无效。
file="${@:1:1}"
params="${@:2}"
echo $file
echo $params
while true ; do
echo +Master $BASHPID
(
echo ++Slave $BASHPID
running=''
stat=''
while true; do
echo RUNNING $running
echo +++Cycle $BASHPID
sleep 1
new_stat="`stat --printf='%Y' "$file"`"
! [ "$stat" = "$new_stat" ] && {
# HERE IS MY ISSUE I DO NOT UNDERSTAND WHY kill -- -"$running" reports process not found . Especially when doing ps f clearly shows both the proper hierarchy and that the PID is as expected .
kill -0 "$running" && pkill -TERM -P "$running"
stat="$new_stat"
echo CHANGE
( /bin/bash "$file" ${params[@]} ) &
running=$!
}
done &
wait
echo Slave/Cycle clear
) &
wait
done
trap "-" EXIT
#stat="`ls`"
运行文件
#!/bin/bash
echo ++++sub $BASHPID
(
while true; do
echo +++++tick $BASHPID
sleep 5
done
) &
wait
echo SUB/tick clear