Skip to content

Process.GetProcesses returns truncated 15 char string on Linux #28346

Closed
dotnet/corefx
#37144

Description

@2E0PGS

When using Process.GetProcesses() in dotnet core it returns the Process.ProcessName property fine under Windows as expected.

However when ran under Linux (Tested on Ubuntu 17.04) it seems to return process names as 15 char long strings. It truncates the process names to all be 15 char long strings.

My applogies if there is an issue for this somewhere under another repo. I found there was such an issue with the mono framework when doing research prior to submitting this issue: https://bugzilla.xamarin.com/show_bug.cgi?id=32539

Activity

  1. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    Thanks for the pointer to the MacOS bug fix. It seems Linux has a similar limit. Here is a process with a 30 character name, only 15 show:

    dan@danmose3:~/git/corefx/src/Native$ cat /proc/10725/stat
    10725 (123456789012345) S 10116 10725 10115 1025 0 0 0 0 0 0 0 0 0 0 20 0 1 0 17132735 97915326464 204 18446744073709551615 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    

    This is because /proc/<PID>/stat gets the value from task_struct which is TASK_COMM_LEN chars (sched.h) which is 16 including null.

  2. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    It looks like /proc/<PID>/exe is one way to get the full file name

    dan@danmose3:~/git/corefx/src/Native$ ls -l /proc/10725/exe
    lrwxrwxrwx 1 dan dan 0 Jan  8 14:38 /proc/10725/exe -> /home/dan/123456789012345678901234567890
    
  3. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    It looks like we already get the full exe path from this file. We just need to use it a few lines higher up (cropping off the path) instead of the stat entry

    https://github.com/dotnet/corefx/blob/e0ba7aa8026280ee3571179cc06431baf1dfaaac/src/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Linux.cs#L76-L85

  4. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    @2E0PGS any interest in making this change, with a unit test?

  5. 2E0PGS commented on Jan 8, 2019

    @2E0PGS
    ContributorAuthor

    Thanks for pulling out those lines and doing a few basic tests.

    I will have a further look at the code base and check what unit tests are in place at the moment.

    I will try give it a shot if I get some free time. Otherwise I will let you know if I am too busy to make the change.

  6. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    OK, thanks. As for Mac it seems we do not use /proc/../stat but it would be nice to have a test (need not be you of course)

  7. danmoseley commented on Feb 2, 2019

    @danmoseley
    Contributor

    @2E0PGS do you think you might give this a go? Let me know if you need pointers getting set up?

  8. 2E0PGS commented on Feb 2, 2019

    @2E0PGS
    ContributorAuthor

    Sorry been very busy. Yes I was just reading the dotnet core wiki for setting up the development environment. Hopefully I can give it a go soon.

  9. 2E0PGS commented on Feb 2, 2019

    @2E0PGS
    ContributorAuthor

    I don't quite know know why the solution doesn't pickup the distro specific cs files.

  10. 2E0PGS commented on Feb 2, 2019

    @2E0PGS
    ContributorAuthor

    Got a build done, just need to see how I am going to run this inplace of regular dotnet core on the system to check it against my test program.

  11. danmoseley commented on Feb 2, 2019

    @danmoseley
    Contributor

    Have you written a unit test? Take a look at existing tests under Systrm.Diagnostics.Process/tests. There are some that launch processes. You could follow the pattern but rename the file to a long name before launching. Or possibly copy "sleep" to a long name version then run it with a large value, read the name, then terminate it and delete it. This assumes all distros have sleep.

  12. 2E0PGS commented on Feb 2, 2019

    @2E0PGS
    ContributorAuthor
  13. 2E0PGS commented on Feb 3, 2019

    @2E0PGS
    ContributorAuthor

    I got this so far: 2E0PGS/corefx@691e55e

    Just need to test this on Linux.

  14. 2E0PGS commented on Feb 3, 2019

    @2E0PGS
    ContributorAuthor

    OK so implementing those changes: 2E0PGS/corefx@e1e308c

    Using my test program the output we had before any of my changes looked like this and it had a name for every process.

    Process name: systemd
    Process name: kthreadd
    Process name: kworker/0:0
    Process name: kworker/0:0H
    

    Using the recent commit I linked above the test program has quite a few processes without names.

    Process name: systemd
    Process name: 
    Process name: 
    Process name: mate-session
    Process name: dbus-daemon
    
  15. 2E0PGS commented on Feb 3, 2019

    @2E0PGS
    ContributorAuthor

    However the names are now longer than 15 chars. We need to investigate why some are blank.

  16. 6 remaining items

  17. danmoseley commented on Feb 20, 2019

    @danmoseley
    Contributor

    Are you suggesting we try Process.GetExePath(processId); and if that's null or blank fall back to procFsStat.comm

    Was out of office -- @2E0PGS yes, I think so. Try that, plus a test?

  18. 2E0PGS commented on Feb 20, 2019

    @2E0PGS
    ContributorAuthor

    I will give that a try soon thanks.

  19. 2E0PGS commented on Feb 24, 2019

    @2E0PGS
    ContributorAuthor

    Just building a new corefx now to test it against a CLI app.

  20. 2E0PGS commented on Feb 24, 2019

    @2E0PGS
    ContributorAuthor

    Ok this commit works well: 2E0PGS/corefx@56e7385

    Test CLI program output:

    Process name: indicator-application-service
    Process name: indicator-session-service
    Process name: indicator-messages-service
    Process name: indicator-sound-service
    Process name: indicator-power-service
    Process name: mate-terminal
    Process name: bash
    Process name: obexd
    Process name: bash
    Process name: htop
    

    No missing process names now.

  21. danmoseley commented on Feb 25, 2019

    @danmoseley
    Contributor

    Great, do you want to create a test and put up a PR?

  22. 2E0PGS commented on Feb 25, 2019

    @2E0PGS
    ContributorAuthor
  23. danmoseley commented on Feb 25, 2019

    @danmoseley
    Contributor

    Thanks @2E0PGS

  24. danmoseley commented on Mar 5, 2019

    @danmoseley
    Contributor

    @2E0PGS hello, are you still working on this one? I think only test remains? You could throw up a PR just for work in progress, that others could comment on.

  25. 2E0PGS commented on Mar 5, 2019

    @2E0PGS
    ContributorAuthor
  26. danmoseley commented on Mar 5, 2019

    @danmoseley
    Contributor

    @2E0PGS totally fine. It's just us keeping the pipes flowing rather than any particular urgency for this one.

  27. transferred this issue fromdotnet/corefxon Feb 1, 2020
  28. added this to the 3.0 milestone on Feb 1, 2020
  29. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions