Skip to content

Starting new Process as not child of the application #104210

Description

@dpeter99

Description

I'm trying to start a new Process in a multiplatform way (Win and Linux) and make the new process not a child process of the running C# App.

I found this code snippet online for running a process as non-child:

ProcessStartInfo psi = new ProcessStartInfo("YourExecutable.exe");
psi.UseShellExecute = true;
Process.Start(psi);

This still spawns the new process as a child process.

After a lot of searching, I ended up with this setup:

var linux = new ProcessStartInfo("/usr/bin/sh", new []
{
    "-c",
    "nohup /usr/bin/java"+
    " -Xmx1024M" +
    " -Xms1024M" +
    " -jar " +
     _serverJar.FullName +
    "" +
    " &"
})
{
     WorkingDirectory = _serverFolder.FullName,
     UseShellExecute = true,
};

However, this is not easily portable and requires the actual arguments to be already concatenated, which makes some mistakes possible.

With this workaround, we also lose the PID of the new process which is a must in my use case.

Reproduction Steps

Try to use the first example to spawn a new process as non-child, on a Linux system.

Expected behavior

There should be an easy way to run a process as non-child that works on all platforms.

Actual behavior

The spawned process is a child of the app and is terminated when the c# app exits.

Regression?

No response

Known Workarounds

It is possible to call /bin/sh with the nohup and & to instruct it to make a new detached process, but this is not a portable setup.

Configuration

.NET 8
Linux (Fedora 40)
x64

Other information

No response

Activity

  1. KalleOlaviNiemitalo commented on Jul 1, 2024

    @KalleOlaviNiemitalo

    The spawned process is a child of the app and is terminated when the c# app exits.

    What terminates it?

  2. dpeter99 commented on Jul 2, 2024

    @dpeter99
    Author

    What terminates it?

    The operating system.

  3. KalleOlaviNiemitalo commented on Jul 2, 2024

    @KalleOlaviNiemitalo

    I'd expect the child process to be reparented to PID 1 (init) and continue running.

    How do you start your C# app? If you start it from a terminal emulator and close the window, then that could cause a SIGHUP to be sent to the processes using that tty, including the child process of your app. Or do you start the app from cron?

  4. dpeter99 commented on Jul 2, 2024

    @dpeter99
    Author

    I tested when starting from Rider IDE, and stopped the app in 3 ways:

    • Rider stop button
    • Let the app exit without doing any await on the Process
    • Sending SIGKILL from htop
      And all of these resulted in the new Process closing
      In my use case, the started "child" process must survive any way the c# app might close/crash
  5. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 16, 2024
  6. added this to the Future milestone on Jul 16, 2024
  7. adamsitnik commented on Jul 16, 2024

    @adamsitnik
    Member

    @dpeter99 thank you for your proposal. For now I'll wait until more customers express the need for such API.

  8. dpeter99 commented on Jul 19, 2024

    @dpeter99
    Author

    @adamsitnik
    What about fixing the UseShellExecute, or do you have any suggestions on how to do it?

  9. KalleOlaviNiemitalo commented on Jul 19, 2024

    @KalleOlaviNiemitalo

    I don't believe UseShellExecute is intended to prevent the new process from being a child of the calling process. Rather, it is a way to start things that are not executable files, such as document files and URLs.

  10. adamsitnik commented on Jan 5, 2026

    @adamsitnik
    Member

    The spawned process is a child of the app and is terminated when the c# app exits.

    As @KalleOlaviNiemitalo wrote, I would expect that app to keep running.

    @dpeter99 what exactly do you want to achieve? nohup seems to be used to keep running the app after user logoff or closing the terminal.

  11. self-assigned this
    on Jan 5, 2026
  12. added
    needs-author-actionAn issue or pull request that requires more info or actions from the author.
    on Jan 7, 2026
  13. removed this from the Future milestone on Feb 4, 2026
  14. adamsitnik commented on Feb 12, 2026

    @adamsitnik
    Member

    Please check #124334 for updates

  15. locked and limited conversation to collaborators on Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions