Skip to content

test-case: Implement one common method for kill process#1352

Open
SzymonRichert wants to merge 1 commit intothesofproject:mainfrom
SzymonRichert:newKillFunction
Open

test-case: Implement one common method for kill process#1352
SzymonRichert wants to merge 1 commit intothesofproject:mainfrom
SzymonRichert:newKillFunction

Conversation

@SzymonRichert
Copy link
Collaborator

@SzymonRichert SzymonRichert commented Mar 9, 2026

This PR replaces all direct usages of kill -9 with a new helper function, kill_process().
The new function introduces a safer and more controlled process‑termination flow, using graceful shutdown attempts before falling back to a forced kill.

Function was tested and it works:
image

Implement one common method for kill process in lib.sh
Replace all kill -9 with kill_process() function in tests.
Method kill_process() try kill -15 first and as a last resort do kill -9.

Signed-off-by: Szymon Richert <szymon1.richert@intel.com>
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was badly needed indeed!

It's really sad Linux forces everyone to reinvent this https://www.freedesktop.org/software/systemd/man/latest/systemd.kill.html


[[ -n "$pid" ]] || {
dloge "kill_process: missing pid"
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would die here because this looks like a serious enough bug.


kill -0 "$pid" 2>/dev/null || return 0

kill -15 "$pid" 2>/dev/null || true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discarding stderr is almost always a bad idea. What unwanted message does this discard?

Suggested change
kill -15 "$pid" 2>/dev/null || true
kill -TERM "$pid" || true

return 1
}

kill -0 "$pid" 2>/dev/null || return 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-0 looks a bit mysterious and it could fail for other reasons. ps is more direct and more obvious:

Suggested change
kill -0 "$pid" 2>/dev/null || return 0
ps -p "$pid" >/dev/null || return 0

https://stackoverflow.com/questions/3043978/how-to-check-if-a-process-id-pid-exists

BTW there is still a race: the process could still exit right after this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants