Skip to content

[API Proposal]: ProcessStartInfo.CreateSuspended, Process.Resume #94127

Description

@sebastienros

Background and motivation

Currently I use ProcessStartInfo/Process.Start to launch processes with overridden environment variables, redirect standard input and output, and so forth.

I now need to use the CREATE_SUSPENDED flag so that I can modify the process after it's created and before it starts actual execution, but there's no way to pass this flag into ProcessStartInfo/Process.Start. Given that I still need to use all the other features of ProcessStartInfo, the only reasonable path I can see forward is to either copy or reimplement the entirety of the System.Diagnostics.Process code.

My proposal would also be cross-platform.

API Proposal

namespace System.Diagnostics
{
    public sealed class ProcessStartInfo
    {
        public bool StartSuspended { get; set; } // name follows the pattern established by StartDetached
    }
}

namespace Microsoft.Win32.SafeHandles
{
    public sealed class SafeProcessHandle
    {
        public void Resume(); // already approved in https://github.com/dotnet/runtime/issues/123380#issuecomment-3880499825
    }
}

API Usage

var process = new Process()
{
    StartInfo = {
        FileName = executable,
        StartSuspended = true,
        CreateNoWindow = true, // for reference only, as it has the same characteristics
    }
};

process.Start();

int currentPriority = getpriority(PRIO_PROCESS, process.Id);
setpriority(PRIO_PROCESS, process.Id, currentPriority + 1);

process.SafeHandle.Resume();

Alternative Designs

The initial proposal included CreateSuspended name, but it's inconsistent with StartDetached (#124334).

An alternative to having Resume method is to extend SafeProcessHandle.Signal with an ability to map PosixSignal.SIGCONT to ResumeThread on Windows.

namespace System.Runtime.InteropServices
{
    public enum PosixSignal
    {
-       [UnsupportedOSPlatform("windows")]
        SIGCONT = -6,
    }
}

I don't think these issues are duplicates since they adopt a different design that doesn't seem to get traction.

#71515
#90581

NB: @hach-que I copied your proposal and tried to make the API easier to get through the review process.

Risks

No response

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Diagnostics.Processin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions