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

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

Closed
1 of 5 tasks
JimChenWYU opened this issue Jun 15, 2023 · 3 comments · Fixed by #1488
Closed
1 of 5 tasks

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

JimChenWYU opened this issue Jun 15, 2023 · 3 comments · Fixed by #1488

Comments

@JimChenWYU
Copy link

JimChenWYU commented Jun 15, 2023

Describe the bug
Why get processName from /proc/(pid)/comm should be at most 14 letters ?

Refs https://github.com/shirou/gopsutil/blob/master/process/process_linux.go#L795

To Reproduce

  1. My python script named admin_worker.py, just example
#!/usr/local/easyops/python/bin/python
# -*- coding: utf-8 -*-

from time import sleep

while True:
  print("process...")
  sleep(1)
  1. Start admin_worker.py
$ chmod +x admin_worker.py
$ ./admin_worker.py
  1. In Linux, running my go program
// `pid` should be found by `ps` command in machine.

proce, _ := process.NewProcess(int32(pid))
name, _ := proce.Name()
fmt.Println(name)

I find the name is /usr/local/easyops/python/bin/python

Expected behavior
I expect the name is admin_worker.py, because i use cat /proc/(pid)/comm in machine, i get my expected value.

Environment (please complete the following information):

  • Windows: [paste the result of ver]
  • Linux: [paste contents of /etc/os-release and the result of uname -a]
  • Mac OS: [paste the result of sw_vers and uname -a
  • FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
  • OpenBSD: [paste the result of uname -a]

os-release

uname -a

Additional context
[Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]

No.

@shirou
Copy link
Owner

shirou commented Jun 18, 2023

Umm. I faintly think there was a reason, but I can't recall the details, and I can not find any comments from GitHub. If no reason, we can remove the limitation.

@Lomanic
Copy link
Collaborator

Lomanic commented Jun 19, 2023

An easy reproducer for python psutil

TMPDIR=$(mktemp -d)
python3 -m venv "$TMPDIR/venv"
"$TMPDIR/venv/bin/pip3" install psutil
cat > "$TMPDIR/loooooooooooooooooooong.py" <<EOF
#!$TMPDIR/venv/bin/python3
import psutil
print(psutil.Process().name())
EOF
chmod +x "$TMPDIR/loooooooooooooooooooong.py"
cp -a "$TMPDIR/loooooooooooooooooooong.py" "$TMPDIR/short.py"
"$TMPDIR/loooooooooooooooooooong.py"
# returns loooooooooooooo
"$TMPDIR/short.py"
# returns short.py

psutil uses /proc/$PID/stat on linux, see https://github.com/giampaolo/psutil/blob/962cb9ad58ca3bc21b20130f435f8d507d931051/psutil/_pslinux.py#L1745 and https://github.com/giampaolo/psutil/blob/962cb9ad58ca3bc21b20130f435f8d507d931051/psutil/_pslinux.py#L1686. man proc documents this property in the /proc/$PID/stat file with

              (2) comm  %s
                     The  filename  of  the executable, in parentheses.  Strings longer than TASK_COMM_LEN (16) characters (including the terminating null byte) are silently truncated.
                     This is visible whether or not the executable is swapped out.

I can't test psutil behaviour on bsd (including darwin), where gopsutil behaviour (aligned with linux, using cmdline as a fallback) is also probably similarly broken (falling back to basename(cmdline[0]), see #796/#795.

What should be done? This is misaligned with psutil (and inconsistent) but changing this behaviour in gopsutil to be the same as in psutil will break backward compatibility downstream.

@JimChenWYU JimChenWYU changed the title Why get processName from /proc/(pid)/comm should be at most 14 letters ? Why get processName from /proc/(pid)/comm should be at most 14 characters ? Jun 20, 2023
Lomanic added a commit to Lomanic/gopsutil that referenced this issue Jul 1, 2023
…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 excutable 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 added a commit to Lomanic/gopsutil that referenced this issue Jul 5, 2023
…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 excutable 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 added a commit to Lomanic/gopsutil that referenced this issue Jul 6, 2023
…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 excutable 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 added a commit to Lomanic/gopsutil that referenced this issue Jul 8, 2023
…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
chenjiandongx added a commit to TencentBlueKing/gopsutil that referenced this issue Aug 29, 2023
* fix some comments

Signed-off-by: cui fliter <[email protected]>

* chore(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.2...v1.8.3)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(mem): Correct capitalization of linux writeback

fixes: shirou#1471

* chore(deps): bump github.com/yusufpapurcu/wmi from 1.2.2 to 1.2.3

Bumps [github.com/yusufpapurcu/wmi](https://github.com/yusufpapurcu/wmi) from 1.2.2 to 1.2.3.
- [Release notes](https://github.com/yusufpapurcu/wmi/releases)
- [Commits](yusufpapurcu/wmi@v1.2.2...v1.2.3)

---
updated-dependencies:
- dependency-name: github.com/yusufpapurcu/wmi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* [common]: fix potential leak on Sleep.

* chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.3...v1.8.4)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* allow to pass context values to override environment variables

* move the Env key out of internal packages

* change to use a typed map per code review

* lint fixes

* remove deprecation comments

* add more env keys

* apply code review

* fix more linting reports

* add(README): add passing context value document

which is introduced by shirou#1439.

* Ref actions by commit SHA in build_test.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/setup-go/releases/tag/v4.0.1
actions/setup-go@fac708d

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5

https://github.com/actions/cache/releases/tag/v3.3.1
actions/cache@88522ab


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in labeler.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/labeler/releases/tag/v4.1.0
actions/labeler@9fcb2c2


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in lint.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/setup-go/releases/tag/v4.0.1
actions/setup-go@fac708d

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5

https://github.com/golangci/golangci-lint-action/releases/tag/v3.5.0
golangci/golangci-lint-action@5f1fec7


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in release.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in sbom_generator.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5

https://github.com/advanced-security/sbom-generator-action/releases/tag/v0.0.1
advanced-security/sbom-generator-action@375dee8

https://github.com/actions/upload-artifact/releases/tag/v3.1.2
actions/upload-artifact@0b7f8ab


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in shellcheck.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5

https://github.com/ludeeus/action-shellcheck/releases/tag/2.0.0
ludeeus/action-shellcheck@00cae50


Signed-off-by: Gabriela Gutierrez <[email protected]>

* Ref actions by commit SHA in test.yml

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/setup-go/releases/tag/v4.0.1
actions/setup-go@fac708d

https://github.com/actions/checkout/releases/tag/v3.5.2
actions/checkout@8e5e7e5

https://github.com/actions/cache/releases/tag/v3.3.1
actions/cache@88522ab


Signed-off-by: Gabriela Gutierrez <[email protected]>

* chore(deps): bump actions/checkout from 3.5.2 to 3.5.3

Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@8e5e7e5...c85c95e)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump golangci/golangci-lint-action from 3.5.0 to 3.6.0

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.5.0 to 3.6.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](golangci/golangci-lint-action@5f1fec7...639cd34)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump golang.org/x/sys from 0.8.0 to 0.9.0

Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.8.0 to 0.9.0.
- [Commits](golang/sys@v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* cpu_percent and memory_percent update

* chore(deps): bump actions/labeler from 4.1.0 to 4.2.0

Bumps [actions/labeler](https://github.com/actions/labeler) from 4.1.0 to 4.2.0.
- [Release notes](https://github.com/actions/labeler/releases)
- [Commits](actions/labeler@9fcb2c2...0967ca8)

---
updated-dependencies:
- dependency-name: actions/labeler
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* [process] Remove all noisy and useless Test_AllProcesses_X tests

These tests can't fail more than their invidiual counterparts and produce an incredibly verbose output

* chore(deps): bump golang.org/x/sys from 0.9.0 to 0.10.0

Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.9.0 to 0.10.0.
- [Commits](golang/sys@v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* [process][posix] Realign process.Name() with python psutil to return 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

* chore(deps): bump actions/labeler from 4.2.0 to 4.3.0

Bumps [actions/labeler](https://github.com/actions/labeler) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/actions/labeler/releases)
- [Commits](actions/labeler@0967ca8...ac9175f)

---
updated-dependencies:
- dependency-name: actions/labeler
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Enable setting of vendor and related information for all Power versions

* chore(deps): bump golang.org/x/sys from 0.10.0 to 0.11.0

Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.10.0 to 0.11.0.
- [Commits](golang/sys@v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* mem: linux: fix vmstat field names

The field names are read from /proc/vmstat were capitalized as their
output fields by mistake

* chore(deps): bump github.com/tklauser/go-sysconf from 0.3.11 to 0.3.12

Bumps [github.com/tklauser/go-sysconf](https://github.com/tklauser/go-sysconf) from 0.3.11 to 0.3.12.
- [Release notes](https://github.com/tklauser/go-sysconf/releases)
- [Commits](tklauser/go-sysconf@v0.3.11...v0.3.12)

---
updated-dependencies:
- dependency-name: github.com/tklauser/go-sysconf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): bump actions/setup-go from 4.0.1 to 4.1.0

Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4.0.1 to 4.1.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](actions/setup-go@fac708d...93397be)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix: fixed windows disk package leaks
- fixed goroutine leak in PartitionsWithContext
- closed registry handle in init

* [host][linux]: remove double quote from lsb release info

fix: shirou#1502

* chore(deps): bump golangci/golangci-lint-action from 3.6.0 to 3.7.0

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.6.0 to 3.7.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](golangci/golangci-lint-action@639cd34...3a91952)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix IOCounters() SerialNumber enumeration

* Update disk/disk_linux.go

Co-authored-by: shirou <[email protected]>

* update comment

* comment cleanup

* chore(deps): bump actions/checkout from 3.5.3 to 3.6.0

Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@c85c95e...f43a0e5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

---------

Signed-off-by: cui fliter <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Gabriela Gutierrez <[email protected]>
Co-authored-by: cui fliter <[email protected]>
Co-authored-by: shirou <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Josh Powers <[email protected]>
Co-authored-by: Antoine Toulme <[email protected]>
Co-authored-by: Gabriela Gutierrez <[email protected]>
Co-authored-by: Elfranne <[email protected]>
Co-authored-by: Lomanic <[email protected]>
Co-authored-by: Kishen V <[email protected]>
Co-authored-by: Hugo Beauzée-Luyssen <[email protected]>
Co-authored-by: Ozan HACIBEKİROĞLU <[email protected]>
Co-authored-by: Greg Dallavalle <[email protected]>
Co-authored-by: Greg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants