-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide way to send Control+C to proccess #14628
Comments
Environment.Exit for current process. We must have a way to close created process |
My understanding is that Windows is inherently different from Unix here. The best way to provide "signaling" abilities to a Windows process is to launch it as a service, as far as I know. Is there a non-hacky way (in any language/API) for one Windows process to kill another? |
How about: Process.Start("taskkill", "/F /IM [taskname].exe");
// Bonus: kills the entire process tree Con: not cross-platform. |
Is there some specific reason why https://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx |
@jthelin is right: Process.GetProcessById (pid, [machinename])
.Kill(); |
Sending The functionality sought by the creator of this topic is provided by @jthelin. A proper way to send control characters to console processes via C#? Write to their standard in pipe. |
Only if the process is reading from stdin. See this and the comment below: http://stackoverflow.com/a/285041
👍 for providing OOTB signaling, which works cross-platform. Mono has its own implementation for Unix signaling: http://www.jprl.com/Blog/archive/development/mono/2008/Feb-08.html. |
FWIW, I worry very much about implementing something like this. The semantic between how this would work on *NIX (where you can actually send an event to a single process) vs Windows, where it goes to possibly multiple process, is worry-some to me. I would much prefer some library outside of the core to handle this. I am glad we also did not expose Process.CloseMainWindow() as part of .NET Core for similar reasons, it would be very hard to support across multiple OSes and App Models. |
Seems related to #14528. |
This is being tracked by dotnet/corefx#3188. |
Sorry, closed prematurely, as the request was for a cross-platform ctrl-C. |
@KindDragon Can you provide an API proposal? A good example here |
Closing as abandoned, feel free to re-open if you plan on working on it. |
To add my input, I am starting processing from a web application (benchmarking them) and can't get anything to work correctly in either windows or linux. P/Invoke, kill -INT, nothing works and it's really an issue for me. The only workaround I got so far is to have an endpoint in these web apps to trigger an internal graceful shutdown, let's call it a backdoor. But I can do this for shell scripts. |
@ellismg @terrajobst @stephentoub we (VS Version Control & Git for Windows) have had to deal with this issue re: Git-bash. We've built up a scary level of knowledge about how Ctrl+C "signals" work on Windows. If / when you need information, feel free to reach out and I can provide a brain dump plus sounding board. Sadly, I've negative spare time to contribute outside my core area at the moment. Quick overview: POSIX API enable sending signals to any process. Windows enables sending signals to any process you own, and have access to their attached console. Windows makes this extra complicated by:
|
At least on Unix, the signals can be handled or ignored by application @sebastienros. You may be to use Mono.Posix but as discussed above, Windows do not really have POSIX signals. |
@whoisj , I would love to take you up on your offer to tap into your knowledge on Ctrl+C "signals" and that brain dump... I am running up against a similar issue to what @sebastienros mentioned, except I am looking to gracefully stop a .NET Core 3.1 process from NodeJS 12+ on Windows. I've been all over through the depths of NodeJS (libuv in C++) and dotnet/runtime trying to find an approach, and am more or less stumped. I am interested in the ability to trigger another process' |
Currently .NET doesn't have way to exit nicely from created console process.
It would be nice if we had a such a method.
It can be implemented following way on Windows: http://stackoverflow.com/a/15281070/61505 , for unix we can call
kill (pid, SIGINT);
http://stackoverflow.com/a/1761182/61505It provide a lot of problems for other users too http://stanislavs.org/stopping-command-line-applications-programatically-with-ctrl-c-events-from-net/
The text was updated successfully, but these errors were encountered: