# Terminating a process on Windows

**URL:** <https://discourse.julialang.org/t/terminating-a-process-on-windows/87481>\
**Category:** General Usage\
**Tags:** shell, pipelines\
**Created:** [September 19, 2022, 3:53pm UTC](https://discourse.julialang.org/t/terminating-a-process-on-windows/87481 "2022-09-19T15:53:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashlin\_Harris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashlin_harris/32/210166_2.png) [@Ashlin\_Harris](https://discourse.julialang.org/u/Ashlin_Harris)\
**Post date:** [September 19, 2022, 3:53pm UTC](https://discourse.julialang.org/t/terminating-a-process-on-windows/87481/1 "2022-09-19T15:53:43Z")

</div>

I’m not able to `kill` a Julia process on Windows. Instead, its status remains as `ProcessSignaled`, and it never terminates. The issue doesn’t exist on MacOS and Linux, and it occurs regardless of Julia version. I didn’t experience this issue last month, and I’m beginning to suspect that this is related to a recent Windows 10 update. Still, I thought I would reach out to the community, in case I am doing something silly ([besides shelling out in the first place!](https://julialang.org/blog/2012/03/shelling-out-sucks/)).

# Minimal nonworking example

```julia-auto
# This command runs silently and terminates on its own
command = "sleep(5)"
# This command prints to the REPL and must be signaled
#command = "while true; print(\"-\"); sleep(1); end"

process = run(pipeline(`julia -e $command`, stdout), wait=false);

# Important: On Windows, this may create a process that doesn't terminate!
kill(process)

```

---

<div class="post-metadata">

**Author:** ![Ashlin\_Harris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashlin_harris/32/210166_2.png) [@Ashlin\_Harris](https://discourse.julialang.org/u/Ashlin_Harris)\
**Post date:** [April 21, 2023, 8:26pm UTC](https://discourse.julialang.org/t/terminating-a-process-on-windows/87481/2 "2023-04-21T20:26:41Z")

</div>

[This thread](https://discourse.julialang.org/t/how-do-i-kill-a-spawned-process/3824) seems be related.

I found [this workaround](https://discourse.julialang.org/t/update-stdout-while-a-function-is-running/86285/9):

```julia
begin
  # Command for drawing a spinner
  command = "
    t=Threads.@async read(stdin, Char)
    while !istaskdone(t)
      for q=['\\\\','|','/','-']
        print('\b',q)
        sleep(0.1)
      end
    end
    exit()"

  # Draw spinner as a separate process
  proc_input = Pipe();
  proc = run(pipeline(`julia -e $command`,stdin = proc_input, stdout = stdout), wait = false)

  sleep(1)
  kill(proc) # Process is signaled, but it keeps running
  sleep(2)
  write(proc_input,'c') # Process finishes when it reads from its stdin
  sleep(0.5)
  println()
end

```

Instead of relying on `kill()`, the main process writes to the `stdin` of the spawned process, and this is interpreted as a sort of kill signal.

In practice, the main drawback is that I haven’t found any way for the spawned process to receive signals both from the user and from the main process.
