Skip to content

Process.Handle does not work on Linux like it does on Windows #28773

Closed

Description

@hanabi1224

When targeting to netcoreapp2.0, below code works fine on windows but not linux, WaitHandle.WaitAll returns immediately on linux instead of waiting for process to actually exit. Is this bug or by design?

    static void Main(string[] args)
    {
        Process p;
        if (Environment.OSVersion.Platform == PlatformID.Win32NT)
        {
            p = Process.Start("timeout", "10");
        }
        else
        {
            p = Process.Start("sleep", "10s");
        }

        var waitHandle = new ManualResetEvent(false);
        waitHandle.SetSafeWaitHandle(new SafeWaitHandle(p.Handle, false));
        WaitHandle.WaitAll(new[] { waitHandle });
        if (!p.HasExited)
        {
            throw new Exception("Process wait handle is not working properly");
        }
        else
        {
            Console.WriteLine("success");
        }
    }

Activity

  1. sunnycase commented on Feb 25, 2019

    @sunnycase
    Contributor

    Try Process.WaitForExit().

  2. hanabi1224 commented on Feb 25, 2019

    @hanabi1224
    Author

    @sunnycase That one works but it's not what I need :(

  3. joshfree commented on Feb 26, 2019

    @joshfree
    Member
  4. changed the title [-]SafeWaitHandle does not work properly on linux[/-] [+]Process.Handle does not work on Linux like it does on Windows[/+] on Feb 26, 2019
  5. self-assigned this
    on Mar 20, 2019
  6. transferred this issue fromdotnet/corefxon Feb 1, 2020
  7. added this to the 3.0 milestone on Feb 1, 2020
  8. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Diagnostics.Processos-linux

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions