Keeping track of processes with `wait=false`

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:

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

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.

image

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.

@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!