Python Exec Linux Process
While I am writing a curses based recording application in Python I thought it a good idea to jot down what I did to call a process and get the pid, then run for a set number of minutes and then kill the pid.
def doit_func(): output = subprocess.check_output(["/usr/bin/v4l2-ctl","--device=/dev/" + cfg_dict['source'],"--set-ctrl=video_bitrate=" + cfg_dict['bitrate']]) tsStream = open(cfg_dict['target'],"wb") catProc = subprocess.Popen(["/bin/cat","/dev/video1","&"], stdout=tsStream) pid = str(catProc.pid) start_time = time.time() elapsed_mins = 0 while elapsed_mins != mins: counter = counter + 1 elapsed_mins = int(time.time() - start_time) / 60 draw_dict("recording for " + str(elapsed_mins) + " mins") output = subprocess.check_output(["/bin/kill","-9",pid])