Open dpeter99 opened 2 months ago
The spawned process is a child of the app and is terminated when the c# app exits.
What terminates it?
What terminates it?
The operating system.
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?
I tested when starting from Rider IDE, and stopped the app in 3 ways:
@dpeter99 thank you for your proposal. For now I'll wait until more customers express the need for such API.
@adamsitnik What about fixing the UseShellExecute, or do you have any suggestions on how to do it?
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.
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:
This still spawns the new process as a child process.
After a lot of searching, I ended up with this setup:
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 thenohup
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