Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 8fdea56

Browse files
committed
added kill-by-pid on Windows
1 parent 3817cda commit 8fdea56

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This is a fork that replaces Lint.jl with StaticLint.jl from the Julia VSCode pl
2424
* The environment for each file is guessed from its path. If this fails, Julia's default environment is assumed.
2525
* The symbols are rebuilt if the modification time of the Project.toml or the Manifest.toml files change, for example,
2626
you add, remove or update packages. Linting is not available during this rebuild.
27-
* It works on Windows, but the Julia server does not shuts down on its own there (yet).
2827

2928
## Internals
3029

@@ -34,7 +33,7 @@ Guessing the environment works by walking upwards in the path and looking for Pr
3433
environment is assumed. The project's root file is then looked for at the canonical X/src/X.jl etc. locations.
3534

3635
I know nothing of Atom development or js, so the changes are likely messy there, please revise. Atom seems to be
37-
unable to shut down the server process, so the server exits by polling Atom's PID right now. This does not work on Windows yet.
36+
unable to shut down the server process, so the server exits by polling Atom's PID right now.
3837

3938
## Installation
4039

lib/julia-server.jl

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,53 @@ end
146146

147147
function exit_if_atom_dies()
148148

149+
HANDLE = Ptr{Cvoid}
150+
DWORD = UInt32
151+
BOOL = Cint
152+
153+
PROCESS_QUERY_INFORMATION = 0x0400
154+
ERROR_INVALID_PARAMETER = 0x57
155+
STILL_ACTIVE = 259
156+
157+
function CloseHandle(handle)
158+
Base.windowserror(:CloseHandle, 0 == ccall(:CloseHandle, stdcall, Cint, (HANDLE,), handle))
159+
nothing
160+
end
161+
162+
function OpenProcess(id::Integer, rights = PROCESS_QUERY_INFORMATION)
163+
proc = ccall((:OpenProcess, "kernel32"), stdcall, HANDLE, (DWORD, BOOL, DWORD), rights, false, id)
164+
Base.windowserror(:OpenProcess, proc == C_NULL)
165+
proc
166+
end
167+
149168
while true
169+
150170
if !Sys.iswindows()
171+
151172
if ccall(:kill, Int32, (Int32, Int32), atom_pid, 0) != 0
152173
exit()
153174
end
175+
154176
else
155-
# need to find a way to test pids on Windows ...
177+
# an Absolutely Ridiculous Difference ...
178+
179+
hProcess = try OpenProcess(atom_pid)
180+
catch err
181+
if err isa SystemError && err.extrainfo.errnum == ERROR_INVALID_PARAMETER
182+
exit()
183+
end
184+
end
185+
186+
exitCode = Ref{DWORD}()
187+
188+
if ccall(:GetExitCodeProcess, stdcall, BOOL, (HANDLE, Ref{DWORD}), hProcess, exitCode) != 0
189+
CloseHandle(hProcess)
190+
if exitCode[] != STILL_ACTIVE
191+
exit()
192+
end
193+
else
194+
CloseHandle(hProcess)
195+
end
156196

157197
end
158198
sleep(5)

0 commit comments

Comments
 (0)