# Keeping track of processes with \`wait=false\`

**URL:** https://discourse.julialang.org/t/keeping-track-of-processes-with-wait-false/54504
**Category:** General Usage
**Created:** [February 3, 2021, 1:43am UTC](https://discourse.julialang.org/t/keeping-track-of-processes-with-wait-false/54504 "2021-02-03T01:43:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)
#### Post date: [February 3, 2021, 1:43am UTC](https://discourse.julialang.org/t/keeping-track-of-processes-with-wait-false/54504/1 "2021-02-03T01:43:49Z")

</div>

Hi all—

I have a little piece of code that that opens up a file using `run(xdg-open $file, wait=false)` (removing the inner back ticks for better rendering). I’d really like to work out some way to keep track of these processes and kill old ones once a certain number are running at the same time and a new one is requested. My current attempt is like this:

```julia
proc = run(`xdg-open $file`, wait=false)
push!(PROCESSES, proc)
if length(PROCESSES) > something
     firstproc = first(PROCESSES)
     deleteat!(PROCESSES, 1)
     kill(firstproc)
end

```

This code runs, and when I look at the status of the thing I called `kill` on it has changed. But the `xdg-open` window is still open. I’ve also tried something like

```julia
proc = run(`xdg-open $file`, wait=false)
push!(PROCESSES, proc)
if length(PROCESSES) > something
     firstproc = first(PROCESSES)
     deleteat!(PROCESSES, 1)
     _pid = getpid(firstproc)
    run(`kill $_pid`)
end

```

But that doesn’t work either, and oddly seems to not work because `getpid` doesn’t return the same pid that I see for the corresponding process in `htop`. So there’s definitely something I’m not understanding. Could somebody provide guidance? From some previous issues here it seems like `wait=false` gives up a lot of control of the process, so I recognize that that makes it more difficult. But I would have thought that the second attempt here should work considering that I can obviously still go to `htop`, find the pid, and kill it myself at a command line.

Thanks in advance for reading.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 3, 2021, 2:44am UTC](https://discourse.julialang.org/t/keeping-track-of-processes-with-wait-false/54504/2 "2021-02-03T02:44:27Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/2/f/2f6447c7edf6c9ed91ac779940c3743f380828b1.png)

notice how the process is instantly finished. Basically the process that starts `xdg-open` doesn’t manage what `xdg-open` actually spawns.

This is the intended behavior of xdg-open, nothing Julia can do here.

---

<div class="post-metadata">

### Author: ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)
#### Post date: [February 3, 2021, 3:06am UTC](https://discourse.julialang.org/t/keeping-track-of-processes-with-wait-false/54504/3 "2021-02-03T03:06:41Z")

</div>

@jling: amazing, thank you. I was trying to be cool using `xdg-open` for at least having some linux portability, but that’s what I get for using it and not really understanding how it works. Thanks so much!
