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
Fix Parent property on processes with complex name #17545
Conversation
| return invalidPid; | ||
| Match ppidMatch = Regex.Match( | ||
| line, | ||
| @"^PPid:\s+(\d+)$", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jborean93 is there any concern using StartsWith() and then splitting out the pid trimming the whitespace instead of a regex?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jborean93 Any chance to get the proposed changes done? Thanks!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@JamesWTruher can you please review this PR? |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Fix the `Parent` property to retrieve the parent process on Linux where the process name has complex characters like a space or parenthesis.
|
Looks like there might be a problem with using |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
Using |
| while true; do sleep 1; done | ||
| '@ | ||
|
|
||
| # Can't use testdrive: as unelevated user doesn't have perms in test in CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reword:
| # 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 @nohwnd
There was a problem hiding this comment.
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.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@daxian-dbw Ready to merge? |
|
Thanks everyone for your reviews and suggestions. |
|
@jborean93 Thanks for your contribution! |


PR Summary
Fix the
Parentproperty to retrieve the parent process on Linux wherethe process name has complex characters like a space or parenthesis.
PR Context
Reads from
/proc/[pid]/statusrather than/proc/[pid]/staton Linux to get the parent process id. Thestatusfile 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 thestatfile.Fixes #12908
Fixes #17541
Alternative to #12925
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).