Skip to content

Fix Parent property on processes with complex name - #17545

Merged
Dongbo Wang (daxian-dbw) merged 6 commits into
PowerShell:masterfrom
jborean93:linux-ppid
Sep 29, 2022
Merged

Dongbo Wang (daxian-dbw) merged 6 commits into
PowerShell:masterfrom
jborean93:linux-ppid

Conversation

@jborean93

Copy link
Copy Markdown
Collaborator

PR Summary

Fix the Parent property to retrieve the parent process on Linux where
the process name has complex characters like a space or parenthesis.

PR Context

Reads from /proc/[pid]/status rather than /proc/[pid]/stat on Linux to get the parent process id. The status file is nicer as each entry is on a newline and has a label making it easier to select the data required. This is an alternative approach to deal with process' with a space and parenthesis in the name avoiding the last index of logic or trying to correctly select the proper column in the stat file.

Fixes #12908
Fixes #17541

Alternative to #12925

PR Checklist

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The proposal looks very expensive. I'd prefer #12925.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is the concern around the regex, the reading of multiple lines or something else? If it's the regex this could be changes to just doing line.StartsWith("PPid: ") and extract it from there but I thought regex gives some nicer validation.

My only concern about #12925 is if any extra entries are added to the stat file in the future that could mess with the LastIndexOf(')') check. I have no idea what the chances are of that happening but the file certainly has had additions in the past so I can't rule it out.

@JamesWTruher James Truher (JamesWTruher) Jul 11, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the additional cost of the regex is probably not worth it as the StartsWith("PPid: ") will do the trick. If you're really stuck on using regex, i'd be much happier if this was compiled once and continually reused.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Jordan Borean (@jborean93) is there any concern using StartsWith() and then splitting out the pid trimming the whitespace instead of a regex?

@jborean93 Jordan Borean (jborean93) Aug 22, 2022 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The regex just ensure it's PPid: digit but considering this is probably mandated in the spec it's probably not something to be concerned about. I can change it to StartsWith("PPid: ") but didn't think regex would be that bad of a performance problem and is somewhat simpler to extract the match.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Jordan Borean (@jborean93) Any chance to get the proposed changes done? Thanks!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry will get to this next week, just on holidays at the moment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Has been updated to use StartsWith instead as per the suggestion.

@ghost ghost added the Review - Needed The PR is being reviewed label Jun 28, 2022
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@daxian-dbw

Copy link
Copy Markdown
Member

James Truher (@JamesWTruher) can you please review this PR?

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 28, 2022
@ghost ghost added the Review - Needed The PR is being reviewed label Jul 6, 2022
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@daxian-dbw Dongbo Wang (daxian-dbw) added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Sep 12, 2022
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Sep 12, 2022
Fix the `Parent` property to retrieve the parent process on Linux where
the process name has complex characters like a space or parenthesis.
@jborean93

Copy link
Copy Markdown
Collaborator Author

Looks like there might be a problem with using testdrive: in Pester. The permissions don't allow an unauthenticated users to set the executable bit breaking the tests for that scenario. Any suggestions on what to do there. I don't fully know how the tests are actually set up here.

@pull-request-quantifier-deprecated

ghost commented Sep 20, 2022

Copy link
Copy Markdown

This PR has 47 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +34 -13
Percentile : 18.8%

Total files changed: 2

Change summary by file extension:
.cs : +13 -6
.ps1 : +21 -7

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@jborean93

ghost commented Sep 20, 2022

Copy link
Copy Markdown
Collaborator Author

Looks like there might be a problem with using testdrive: in Pester

Using /tmp as the path was enough to get it passing. Because it only runs on non-Windows that should be fine.

ghost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM in common.

If we don't want extra allocations, we could replace Split() by ReadonlySpan.TrimStart()

while true; do sleep 1; done
'@

# Can't use testdrive: as unelevated user doesn't have perms in test in CI

ghost Sep 21, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please reword:

Suggested change
# Can't use testdrive: as unelevated user doesn't have perms in test in CI
# Can't use 'Testdrive:' as unelevated user doesn't have permissions to do 'chmod'.

I guess it is because .Net 7 RC1 has a breaking change in Directory.Create() where chmod mask was changed. If so, it might still break something in PowerShell or Pester.
/cc Jakub Jareš (@nohwnd)

ghost Sep 21, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I assumed this was just a byproduct of how PowerShell CI is set up. I've not looked into it but I believe the unelevated user may potentially be inheriting the same tmpdir as the elevated account and thus cannot set the execute bit on files in that dir. This is just a guess so your assumption could also be true.

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 21, 2022

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ghost ghost added the Review - Needed The PR is being reviewed label Sep 29, 2022
@ghost

ghost commented Sep 29, 2022

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov

ghost commented Sep 29, 2022

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Ready to merge?

@ghost ghost removed the Review - Needed The PR is being reviewed label Sep 29, 2022
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit d66b2a5 into PowerShell:master Sep 29, 2022
@jborean93
Jordan Borean (jborean93) deleted the linux-ppid branch September 29, 2022 04:48
@jborean93

ghost commented Sep 29, 2022

Copy link
Copy Markdown
Collaborator Author

Thanks everyone for your reviews and suggestions.

@iSazonov

ghost commented Sep 29, 2022

Copy link
Copy Markdown
Collaborator

Jordan Borean (@jborean93) Thanks for your contribution!

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

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parent Process Object is Missing Process.Parent property is null on Linux if the process name contains a space

5 participants