{"id":46,"date":"2012-11-06T01:57:41","date_gmt":"2012-11-06T09:57:41","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=46"},"modified":"2012-11-06T02:57:33","modified_gmt":"2012-11-06T10:57:33","slug":"python-exec-linux-process","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/python-exec-linux-process\/","title":{"rendered":"Python Exec Linux Process"},"content":{"rendered":"
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.<\/p>\n
def doit_func():\r\noutput = subprocess.check_output([\"\/usr\/bin\/v4l2-ctl\",\"--device=\/dev\/\" + cfg_dict['source'],\"--set-ctrl=video_bitrate=\"\r\n + cfg_dict['bitrate']])\r\n\r\n tsStream = open(cfg_dict['target'],\"wb\")\r\n\r\n catProc = subprocess.Popen([\"\/bin\/cat\",\"\/dev\/video1\",\"&\"], stdout=tsStream)\r\n pid = str(catProc.pid) \r\n\r\n start_time = time.time()\r\n elapsed_mins = 0\r\n\r\n while elapsed_mins != mins:\r\n counter = counter + 1\r\n elapsed_mins = int(time.time() - start_time) \/ 60\r\n draw_dict(\"recording for \" + str(elapsed_mins) + \" mins\")\r\n\r\n output = subprocess.check_output([\"\/bin\/kill\",\"-9\",pid])<\/pre>\n","protected":false},"excerpt":{"rendered":"While I am writing a curses based recording application in Python I thought it a good idea to jot down<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}