test-case: Implement one common method for kill process#1352
Open
SzymonRichert wants to merge 1 commit intothesofproject:mainfrom
Open
test-case: Implement one common method for kill process#1352SzymonRichert wants to merge 1 commit intothesofproject:mainfrom
SzymonRichert wants to merge 1 commit intothesofproject:mainfrom
Conversation
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>
arikgreen
approved these changes
Mar 9, 2026
marc-hb
reviewed
Mar 9, 2026
Collaborator
marc-hb
left a comment
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
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 |
Collaborator
There was a problem hiding this comment.
-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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
