You have to keep track of it yourself. The shell keeps track of all of its subprocess jobs, but you're not a shell, so you have to do the tracking yourself. jobs
is a Bash shell builtin command, not an actual executable which is run. When you do subprocess.Popen(['jobs'], shell=True)
, you're spawning a new shall and asking it for its jobs, which is of course empty since it's a new shell without any running jobs.
If you can't keep track of your own running jobs, you're going to have a harder time. On Linux, you could parse /proc
and look for all processes which have you as a parent. On Windows, you could do something like this using a wrapper such as pywin32 or the ctypes
module to access the Win32 API.