# List all live(non gc'ed) tasks?

**URL:** https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217
**Category:** Internals & Design
**Created:** [February 20, 2018, 10:49pm UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217 "2018-02-20T22:49:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)
#### Post date: [February 20, 2018, 10:49pm UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/1 "2018-02-20T22:49:23Z")

</div>

Is there a way to get a list of all “live” tasks in the current session?

---

<div class="post-metadata">

### Author: ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)
#### Post date: [August 18, 2018, 9:05pm UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/2 "2018-08-18T21:05:03Z")

</div>

I’ve been looking into Julia’s task management code lately. I don’t have the full picture yet but I think this is hard beacuse there isn’t a master list of tasks.

Say I create a `Condition` and a `Task` that waits on it:

```julia
julia> c = Condition()
julia> t = @async begin
    wait(c)
    println("finished waiting")
end

```

When I run the `@async` my new `Task` is created and added to the `Workqueue` (a queue of runnable tasks). When my current `Task` needs to `wait` for something (e.g. keyboard input at the REPL), it will pop off `t` and switch to it. When `t` runs it will call `wait(c)`, adding itself to `c`’s queue. At this point you could consider `t` to be a “live” task, but it’s not stored in some global list, the only reference to it (aside from in our REPL session) is within `c`’s wait queue.

I think that to do this you’d need to do a full heap search starting at the GC roots (like a GC “mark” phase) and find all the `Task` objects in `:runnable`, `:waiting` or `:queued` states.

I’ve definitely thought it would be useful to have a `top`-style list of active tasks (and ideally be able to kill them selectively), but that would probably require a step where all `Task`s register themselves with some global list on creation.

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [June 28, 2023, 7:32am UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/3 "2023-06-28T07:32:51Z")

</div>

@ssfrr old topic, but I am running into the same demand today - do you have some tips on how to do the heap search?

---

<div class="post-metadata">

### Author: ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)
#### Post date: [June 28, 2023, 10:32am UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/4 "2023-06-28T10:32:36Z")

</div>

Sorry, I don’t think I ever followed this through.

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [June 28, 2023, 10:43am UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/5 "2023-06-28T10:43:45Z")

</div>

I think it would be to use Julia’s builtin profilers together with a visualizer like [GitHub - JuliaPerf/PProf.jl: Export Julia profiles to the pprof format](https://github.com/JuliaPerf/PProf.jl) (supports allocations). The vscode extension has their own visualization with [`@profview_allocs`](https://github.com/julia-vscode/julia-vscode/pull/2890).

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [July 1, 2023, 6:53am UTC](https://discourse.julialang.org/t/list-all-live-non-gced-tasks/9217/6 "2023-07-01T06:53:12Z")

</div>

You could post-procesa the heap snapshot.
