diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs index dcac67a71d..5421991dee 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs @@ -11,6 +11,7 @@ using System.Security.Principal; using System.Threading; using System.Threading.Tasks; +using System.Text.RegularExpressions; namespace Microsoft.Diagnostics.NETCore.Client { @@ -297,7 +298,18 @@ private static bool TryGetDefaultAddress(int pid, out string defaultAddress) { try { - defaultAddress = Directory.GetFiles(IpcRootPath, $"dotnet-diagnostic-{pid}-*-socket") // Try best match. + string status = File.ReadAllText($"/proc/{pid}/status"); + + Regex regex = new Regex(@"^NSpid:.*(\d+)$", RegexOptions.Multiline); + Match match = regex.Match(status); + + int nspid = pid; + if (match.Success) + { + nspid = int.Parse(match.Groups[1].Value); + } + + defaultAddress = Directory.GetFiles($"/proc/{pid}/root/tmp", $"dotnet-diagnostic-{nspid}-*-socket") // Try best match. .OrderByDescending(f => new FileInfo(f).LastWriteTime) .FirstOrDefault(); }