Repository navigation
Fix: Process.Parent property is null on Linux if the process name contains a space - #12925
Rajdeep Biswas (rajdeep-biswas) wants to merge 7 commits into
Conversation
Hi, I went through the testing guide but couldn't find an exact detail of how to add a test to the code, could you please point me to an example? |
|
@therajdeepbiswas You should add a test to Get-Process.Tests.ps1 file.
|
Ilya (@iSazonov) I don't think it is possible to assign an alias with special characters from within PowerShell (so as to be executed from a testcase). I thought it would be better to create a temporary file for one manual test. After executing this from bash, it launched PowerShell as expected and on running And indeed the issue seems to have been solved from the one manual test, as shown below. I don't think including this one file to run testcases on it time and again makes any sense. So it will be unnecessary to include the hardcoded testcase, however, I have added a testcase that checks if the parent property returned is not not null when looked up using process name (and not process ID). Adding in next commit. |
|
The CI test for macos is failing on a pester file I did not change anything in. Please suggest me how to fix this. |
…ocess.Tests.ps1 made changes as suggested Co-authored-by: Ilya <darpa@yandex.ru>
|
Lmao |
|
Ilya (@iSazonov) what now? |
|
@therajdeepbiswas Please fix the test and make the test positive to cover the new code path.
|
Ilya (@iSazonov) My test file, in itself is working when executed offline using
and, as I mentioned earlier, the build was failing on a test file I hadn't modified at all. Please note that
PS: also, I'm not sure what you mean by 'cover the new code path', could you please care to elaborate? |
It is because there is a bug in .Net. (Process name is "ConsoleHost mai".) After the bug will be fixed your test will pass. You should create a process name so that your new code is executed in the new test. |
By this do you mean a test that invokes the Get-Process function which I modified? |
|
Yes. You could use Bash sample you mentioned above. |
|
That can only be done through a manual test, right? How can you write a pester test that executes a custom bash file? |
|
You can create a bash script file on fly, set exec flag by chmod +x and run the script from pwsh. |
|
Ilya (@iSazonov) please check if this is what you are talking about. |
|
Ilya (@iSazonov) Done as you suggested. Please check. |
|
@therajdeepbiswas Please have a look at the failures. |
|
Hi Aditya Patwardhan (@adityapatwardhan)
And about the linux fails, I think they're because of an unbuilt version of pwsh. (The pwsh in the current branch is still running the version that is not bug free, right?) |
Waiting on confirmation about this, Ilya (@iSazonov) |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@therajdeepbiswas Since we moved to .Net 6.0 please rebase. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@therajdeepbiswas yes, please rebase. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@therajdeepbiswas The test you have added is failing please have a look. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
| It "Has Parent process property in linux" -Skip:(-not $IsLinux) { | ||
| # Added new test to check for bug as described in issue https://github.com/PowerShell/PowerShell/issue/12908 | ||
| $powershellexe = (Get-Process -Name "$((Get-Process -Id $PID).Name)").mainmodule.filename | ||
| & $powershellexe -noprofile -command "Set-Content -Path .\'t ( e ( s ) t ).txt' -Value '#!/bin/bash`r`n./$PSHOME/pwsh`r`nchmod +x ./ " + "'t ( e ( s ) t )\'" |
There was a problem hiding this comment.
You don't and shouldn't create a new pwsh to run these commands. Here's what I recommend changing this to (you'll need to test this as I'm typing it freehand in this edit box):
$commandName = 't ( e ( s ) t )'
$script = @"
#!/bin/sh
pwsh -noprofile -command 'while ($true) { Start-Sleep -Seconds 10 }'
"@
Set-Content -Path testdrive:/$commandName -Value $script
chmod +x (resolve-path testdrive:/$commandName -Relative)
try {
$p = start-process -FilePath testdrive:/$commandName -PassThru
(Get-Process $commandName).Parent | Should -Be $pid
}
finally {
$p | Stop-Process
}|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |



PR Summary
Changed code in CorePsPlatform.cs so that process names with spaces in them can be handled.
PR Context
Fix for #12908
This was caused by the inconsistency in the index position after split, which has been fixed here by only considering the substring which stats after the last closing parenthesis ')' and hence it will always have a consistent index for process ID after split()ing.
Note: first ever PR, please be lenient with my documentation. I'm open to suggestions for any changes.
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.