Ok, this is a bit of a thorny problem. I need to launch a backgrounded process that will (1) wait N secs, and then (2) execute some command. Additionally, I need to capture the pid of the background process itself, because when the parent process finishes it will kill the backgrounded process if necessary. It looks a bit like this in shell syntax:
(sleep 15 && run_some_cmd) & # launch bg process
bg_pid=$! # capture the bg pid
# do some stuff here...
kill -9 $bg_pid # and kill the bg_pid if necessary
So that's the launch in shell. However, I'm trying to do this in Python. The tricky thing is that since I need to capture the bg pid, I can't use os.system() or os.fork(), since in each case the parent process does not have access to the pid of the child. I'm trying to get it to work with subprocess.Popen(), but it's a bit tricky given the "sleep 15" portion.
Any ideas?