Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[process][posix] Realign process.Name() with python psutil to return same value on python3 scripts processes #1488

Merged
merged 2 commits into from Jul 30, 2023

Conversation

Lomanic
Copy link
Collaborator

@Lomanic Lomanic commented Jul 1, 2023

e2c79a1 started to blindly set the process name to the full path (instead of the basename) of the cmdline exectuable
if the process name from the process comm was truncated on linux. Python psutil never did that, and this is just wrong
for python (or any executable interpreted script) where the process name is not the interpreter binary but the script
itself.

A new test to check process name value against psutil value is added here, which would hopefully catch any potential
future changes in psutil.

Reverts #542

Fixes #1485

These tests can't fail more than their invidiual counterparts and produce an incredibly verbose output
@Lomanic Lomanic force-pushed the issue1485 branch 2 times, most recently from 056d177 to 2b6de69 Compare July 6, 2023 08:18
Copy link
Owner

@shirou shirou left a comment

Choose a reason for hiding this comment

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

Awesome! I confirmed it works on my FreeBSD 12.4-RELEASE-p1.

% go test -run Test_Process_Name_Against_Python -v
=== RUN   Test_Process_Name_Against_Python
    process_test.go:435: pyName python3.9
--- PASS: Test_Process_Name_Against_Python (0.16s)
PASS
ok      github.com/shirou/gopsutil/v3/process   0.166s

And I am very impressed with the testing idea in this PR, which is to compare directly with psutil results. Perhaps we should extend this idea to other tests.

…same value on python3 scripts processes

e2c79a1 started to blindly set the process name to the full path (instead of the basename) of the cmdline exectuable
if the process name from the process comm was truncated on linux. Python psutil never did that, and this is just wrong
for python (or any executable interpreted script) where the process name is not the interpreter binary but the script
itself.

A new test to check process name value against psutil value is added here, which would hopefully catch any potential
future changes in psutil.

Reverts shirou#542

Fixes shirou#1485
@Lomanic
Copy link
Collaborator Author

Lomanic commented Jul 30, 2023

Thanks for the kind words and testing on freebsd @shirou, I was only able to test on linux. Interestingly your test shows that process comm (name) is set to the interpreter binary basename on freebsd as opposed to the script basename on linux.

Is it OK to merge or do you think we should test on more platforms?

Perhaps we should extend this idea to other tests.

Indeed. We could have automated tests against python psutil on various platfoms, set up on CI even.

@shirou shirou merged commit 0b4d681 into shirou:master Jul 30, 2023
19 checks passed
@shirou
Copy link
Owner

shirou commented Jul 30, 2023

merged. Thank you so much!

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

Successfully merging this pull request may close these issues.

Why get processName from /proc/(pid)/comm should be at most 14 characters ?
2 participants