runtime: Why System.Diagnostics.Process.MainWindowTitle returns empty string on Linux?

System.Diagnostics.Process.MainWindowTitle is empty for all processes on Linux, even when the application has root rights. Tested on Ubuntu 19.10 64bit with .NET Core 3.1 console application.

Repro

sudo ./ConsoleApp2

class Program
    {
        static void Main(string[] args)
        {
            var procs = Process.GetProcesses();
            foreach (var proc in procs)
            {
                Console.WriteLine($"Process: {proc.ProcessName}, MainWindowTitle: {(string.IsNullOrEmpty(proc.MainWindowTitle) ? "<EMPTY>" : proc.MainWindowTitle)}");
            }
        }
    }

Result:

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

If the associated process does not have a main window (so that MainWindowHandle is zero), MainWindowTitle is an empty string (“”).

My conclusion from this is that if you get an empty string, there shouldn’t be a main window. I don’t believe this is “following suit with the docs”. I put in a PR for the docs.

By design it is currently hardcoded to return string.Empty for lack of something better and general enough:

Then you should update the docs to reflect that? https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.mainwindowtitle?view=netcore-3.1