Skip to content

Commit 3ed93a0

Browse files
Nicklee007nicklixinyang
and
nicklixinyang
authored
Fix the pid occupied check when use bookkeeper-daemon.sh start or stop (apache#3113)
Master Issue: apache#3112 ### Motivation Fix the failed pid occupied check. we'll fail when use bookkeeper-daemon.sh start or stop bookie, after the last time we exit the bookie direct kill or the bookie occurred non-normal exit, then the bin/bookkeeper-bookie.pid are retained, and the pid in the file is occupied by the thread in other progress. ### Changes Change the pid occupied check from 'kill -0 $pid' to 'ps -p $pid'. The both will return true when the pid is occupied by one progress, but 'kill -0 $pid' will return true and the 'ps -p $pid' will return false when the pid is occupied by one progress's sub thread. StackOverflow discussion: https://stackoverflow.com/questions/30958964/why-do-kill-0-pid-echo-and-ps-ppid-echo-sometimes-differ Co-authored-by: nicklixinyang <nicklixinyang@didiglobal.com>
1 parent d7328a5 commit 3ed93a0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

bin/bookkeeper-daemon.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ start()
112112
{
113113
if [ -f $pid_file ]; then
114114
PREVIOUS_PID=$(cat $pid_file)
115-
if kill -0 $PREVIOUS_PID > /dev/null 2>&1; then
115+
if ps -p $PREVIOUS_PID > /dev/null 2>&1; then
116116
echo $command running as process $PREVIOUS_PID. Stop it first.
117117
exit 1
118118
fi
@@ -125,7 +125,7 @@ start()
125125
echo $! > $pid_file
126126
sleep 1; head $out
127127
sleep 2;
128-
if ! kill -0 $! > /dev/null ; then
128+
if ! ps -p $! > /dev/null ; then
129129
exit 1
130130
fi
131131
}
@@ -134,13 +134,13 @@ stop()
134134
{
135135
if [ -f $pid_file ]; then
136136
TARGET_PID=$(cat $pid_file)
137-
if kill -0 $TARGET_PID > /dev/null 2>&1; then
137+
if ps -p $TARGET_PID > /dev/null 2>&1; then
138138
echo stopping $command
139139
kill $TARGET_PID
140140

141141
count=0
142142
location=$BOOKIE_LOG_DIR
143-
while kill -0 $TARGET_PID > /dev/null 2>&1;
143+
while ps -p $TARGET_PID > /dev/null 2>&1;
144144
do
145145
echo "Shutdown is in progress... Please wait..."
146146
sleep 1
@@ -155,7 +155,7 @@ stop()
155155
echo "Shutdown completed."
156156
fi
157157

158-
if kill -0 $TARGET_PID > /dev/null 2>&1; then
158+
if ps -p $TARGET_PID > /dev/null 2>&1; then
159159
fileName=$location/$command.out
160160
# Check for the java to use
161161
if [[ -z ${JAVA_HOME} ]]; then

0 commit comments

Comments
 (0)