I want to do a terminal command (on linux) with a timeout. I know there is not a timeout built into the run command so I was trying to do something to make one. So basically I tried:
function run_with_timeout(command::String, timeout::Integer = 5)
cmd = run(`$command`; wait = false)
for i in 1:timeout
if success(cmd) return :success end
sleep(1)
end
kill(cmd)
return :failed
end
command = "sleep 3"
run_with_timeout(command)
This doesn’t work because success(cmd) waits until the process finishes rather than immediately saying whether or not the process has finished yet.
Is there a function that immediately says whether or not a process is finished yet? Any other way to achieve this goal?