Skip to content
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

bin\crystal run wrapper does not terminate if interrupts are ignored #14960

Open
HertzDevil opened this issue Sep 3, 2024 · 4 comments
Open

Comments

@HertzDevil
Copy link
Contributor

If Ctrl+C is ignored, naturally it becomes impossible to terminate the file being executed with crystal run using that shortcut. The same also applies to the bin/crystal script, because it uses exec to run the compiler, but not to bin\crystal.bat and bin\crystal.ps1, since Windows does not have a real exec equivalent. Thus if the following script is run:

Process.ignore_interrupts!
sleep
# minimal alternative for the empty prelude

lib LibC
  alias DWORD = UInt32
  alias BOOL = Int32

  fun SetConsoleCtrlHandler(handlerRoutine : DWORD -> BOOL, add : BOOL) : BOOL
  fun Sleep(dwMilliseconds : DWORD)
end

LibC.SetConsoleCtrlHandler(nil, 1)
LibC.Sleep(-1)

then Ctrl+C still exits the wrapper, leaving both the compiler and the compiled code running. This is problematic because if the user then attempts to run the same code again, a linker error occurs as overwriting a running process's file is not allowed on Windows. The only way out is to manually terminate the running code from Task Manager.

@stakach
Copy link
Contributor

stakach commented Sep 3, 2024

Could always use job objects on Windows
#14839 (comment)

@HertzDevil
Copy link
Contributor Author

There are no job objects from the shell.

@stakach
Copy link
Contributor

stakach commented Sep 4, 2024

@HertzDevil you can try this example script I wrote:
https://gist.github.com/stakach/396a623cc102679136af29ded5a4d004

It launches cmd.exe - you can then launch a bunch of applications msinfo32, notepad etc
then if you close cmd.exe or press ctrl-c on the script all the applications in the process tree will exit

Is this something close to what you were hoping to achieve?

@HertzDevil
Copy link
Contributor Author

The point is that you are not supposed to be able to use Ctrl+C in the first place, because the code says so. It is perfectly fine to terminate the running code process using Task Manager or taskkill and the compiler will automatically exit. This is never a problem about the parent process not killing the child process on exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants