# Best practice for dealing with "Killed" of Julia exits

**URL:** <https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745>\
**Category:** General Usage\
**Tags:** performance, memory, crash\
**Created:** [March 8, 2023, 4:21pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745 "2023-03-08T16:21:27Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 4:21pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/1 "2023-03-08T16:21:27Z")

</div>

Sometimes when I run a Julia script in the terminal, e.g. `julia my_script.jl` the program will exit with a simple `Killed` message, e.g:

![image](https://global.discourse-cdn.com/julialang/original/3X/7/d/7d7da0a280b308c6dfec8e0f271f9936b78eae06.png)

Presumably, this is because I ran something very heavy and this just crashed stuff. Is there some recommendation/best practice for figuring out what caused this? Are there several possible causes for the `Killed` interruption, or am I probably looking at the process having run out of memory?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 8, 2023, 4:25pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/2 "2023-03-08T16:25:57Z")

</div>

This almost always is an out of memory error.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 4:31pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/3 "2023-03-08T16:31:56Z")

</div>

So basically, I either run it on a machine with more memory, or figure out a way fo it to use less memory?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 8, 2023, 4:37pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/4 "2023-03-08T16:37:16Z")

</div>

Probably option 2. Unless you were running it on a machine with only like 8GB of memory, there is only a small chance “more memory” is going to solve the problem.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 4:38pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/5 "2023-03-08T16:38:25Z")

</div>

Thanks a lot, this is very helpful 🙂

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 8, 2023, 5:34pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/6 "2023-03-08T17:34:04Z")

</div>

OK, but why not provide a bit more information in the error message?  
I guess the Julia process is sent a signal to “die”. Could this signal be reported?

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 5:55pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/7 "2023-03-08T17:55:54Z")

</div>

Yeah, this was my problem. Usually, Julia provides errors, but when this happens it just says “Killed” with no further information, giving me no good idea of how to start debugging.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 8, 2023, 6:10pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/8 "2023-03-08T18:10:02Z")

</div>

Julia isn’t giving you the error message. Your OS is. I don’t believe an OOM can be handled by a program.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 8, 2023, 6:16pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/9 "2023-03-08T18:16:49Z")

</div>

At least on Linux, I had a program that was written to catch ctrl-c and respond with a menu.  
Not sure if the out-of-memory signal is “catchable”, at the moment.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 8, 2023, 6:21pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/10 "2023-03-08T18:21:09Z")

</div>

Actually, Julia itself is quite capable of detecting that condition: `LoadError: OutOfMemoryError() `.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 6:27pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/11 "2023-03-08T18:27:16Z")

</div>

Got it, but if Julia can display a `LoadError: OutOfMemoryError()`, is there a reason it doesn’t use it?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 8, 2023, 6:28pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/12 "2023-03-08T18:28:26Z")

</div>

`OutOfMemoryError` can only be thrown when Julia tries to allocate and the allocation fails. You get OOMed when you write to a page that previously had no data given to it so the OS didn’t actually have any pages free even though it promised you it would.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [March 8, 2023, 6:29pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/13 "2023-03-08T18:29:39Z")

</div>

Ok, got it.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 8, 2023, 8:03pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/14 "2023-03-08T20:03:44Z")

</div>

I think OOM killer sends a SIGTERM signal.  
Julia should be able to catch that

---

<div class="post-metadata">

**Author:** ![colintbowers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colintbowers/32/8033_2.png) [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Post date:** [March 9, 2023, 5:10am UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/15 "2023-03-09T05:10:09Z")

</div>

When I get these, I usually throw some println statements into my program so I know roughly whereabouts it is up to at any given time, and then I run the routine in a terminal, and simultaneously keep a system monitor window (on Linux - but I’m sure there is a Windows equivalent) open next to my running program, so I can get a feel for what is causing the memory problems.

If you need to go deeper than that, then [ProfileView.jl](https://github.com/timholy/ProfileView.jl) is a good place to start.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 9, 2023, 12:14pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/16 "2023-03-09T12:14:17Z")

</div>

I don’t think so, as far as I’m aware it sends a SIGKILL (which you can’t recover from). Giving control back to the program when the OS has already decided to (forcefully) stop your code doesn’t really make sense. If it were different, we’d call it the OOM hinter, not the OOM killer.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [March 9, 2023, 3:12pm UTC](https://discourse.julialang.org/t/best-practice-for-dealing-with-killed-of-julia-exits/95745/17 "2023-03-09T15:12:14Z")

</div>

13.4 here: [Out Of Memory Management](https://www.kernel.org/doc/gorman/html/understand/understand016.html)
