# Should Julia be able to (really) kill a worker?

**URL:** https://discourse.julialang.org/t/should-julia-be-able-to-really-kill-a-worker/39564
**Category:** Internals & Design
**Tags:** question, distributed
**Created:** [May 16, 2020, 1:05am UTC](https://discourse.julialang.org/t/should-julia-be-able-to-really-kill-a-worker/39564 "2020-05-16T01:05:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [May 16, 2020, 1:05am UTC](https://discourse.julialang.org/t/should-julia-be-able-to-really-kill-a-worker/39564/1 "2020-05-16T01:05:07Z")

</div>

There is a [`Base.kill`](https://docs.julialang.org/en/v1/base/base/#Base.kill-Tuple%7BBase.Process,Integer%7D) method that kills a `Process`. `Distributed` has a [`rmprocs`](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.rmprocs) method that _tries_ to kill a worker but fails in many situations.

A [`rmprocs`](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.rmprocs) call is not able to kill the worker if it is running a Julia code that does not [`yield`](https://docs.julialang.org/en/v1/base/parallel/#Base.yield) or that is running C code underneath. There is no way (AFAIK) of getting a `Process` object from an worker. There is a [`Base.Libc.getpid`](https://docs.julialang.org/en/v1/base/base/#Base.Libc.getpid) that can be run on the worker, but there is no way to get a `Process` (AFAIK) from it (so [`Base.kill`](https://docs.julialang.org/en/v1/base/base/#Base.kill-Tuple%7BBase.Process,Integer%7D) cannot be called using it).

Underneath the [`Base.kill`](https://docs.julialang.org/en/v1/base/base/#Base.kill-Tuple%7BBase.Process,Integer%7D) there is a `ccall(:uv_process_kill, Int32, (Ptr{Cvoid}, Int32), p.handle, signum)`, that [seems to be equivalent](https://stackoverflow.com/a/43535299) to `ccall(:uv_kill, Cint, (Cint, Cint), worker_pid, signum)` (where `worker_pid` is the result from calling [`Base.Libc.getpid`](https://docs.julialang.org/en/v1/base/base/#Base.Libc.getpid) inside the worker). The `ccall(:uv_kill, ...)` is already possible to do in Julia because `libuv` is used internally, but this is a implementation detail, so it should not be relied upon.

My question (finally) is: as there is machinery inside Julia to kill a process in a OS independent way, and it will probably stay (as [`Base.kill`](https://docs.julialang.org/en/v1/base/base/#Base.kill-Tuple%7BBase.Process,Integer%7D) needs to be implemented some way) would it not be nice to extend it just a little to be able to kill workers from `Distributed` or just anything you are able to run [`Base.Libc.getpid`](https://docs.julialang.org/en/v1/base/base/#Base.Libc.getpid) inside?

Sorry if I am missing something obvious.
