{"id":1947,"date":"2009-11-12T00:21:05","date_gmt":"2009-11-12T07:21:05","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=1947"},"modified":"2020-07-25T22:48:45","modified_gmt":"2020-07-26T05:48:45","slug":"process-of-confusion","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/process-of-confusion\/","title":{"rendered":"Process of Confusion"},"content":{"rendered":"<p>I am working hard at designing a better <a href=\"http:\/\/fate.multimedia.cx\/\">FATE<\/a> right now. But first thing&#8217;s first: I&#8217;m revisiting an old problem and hoping to conclusively determine certain process-related behavior.<\/p>\n<p><a href=\"http:\/\/multimedia.cx\/eggs\/processing-those-crashers\/\">I first described the problem in this post<\/a> and claimed in <a href=\"http:\/\/multimedia.cx\/eggs\/fates-further-evolution\/\">this post that I had hacked around the problem.<\/a> Here&#8217;s the thing: When I spin off a new process to run an FFmpeg command line, Python&#8217;s process object specifies a PID. Who does this PID belong to? The natural assumption would be that it belongs to FFmpeg. However, I learned empirically that it actually belongs to a shell interpreter that is launching the FFmpeg command line, which has a PID 1 greater than the shell interpreter. So my quick and dirty solution was to assume that the actual FFmpeg PID was 1 greater than the PID returned from Python&#8217;s subprocess.Popen() call.<\/p>\n<p><em>Bad assumption.<\/em> The above holds true for Linux but not for Mac OS X, where the FFmpeg command line has the returned PID. I&#8217;m not sure what Windows does.<\/p>\n<p>This all matters for the timeout killer. FATE guards against the possibility of infinite loops by specifying a timeout for each test. Timeouts don&#8217;t do much good when they trigger TERM and KILL signals to the wrong PID. I tested my process runner carefully when first writing FATE (on Linux) and everything worked okay with using the same PID returned by the API. I think that was because I was testing the process runner using the built-in &#8216;sleep&#8217; shell command. This time, I wrote a separate program called &#8216;hangaround&#8217; that takes a number of seconds to hang around before exiting. This is my testing methodology:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/multimediamike\/f0edc5b992c50b9333f8f56d92a1a359.js\"><\/script><\/p>\n<p>From another command line:<\/p>\n<pre>\r\n$ ps ax|grep hangaround\r\n21433 pts\/2    S+     0:00 \/bin\/sh -c .\/hangaround 30\r\n21434 pts\/2    S+     0:00 .\/hangaround 30\r\n21436 pts\/0    R+     0:00 grep hangaround\r\n<\/pre>\n<p>That&#8217;s Linux; for Mac OS X:<\/p>\n<pre>\r\n>>> process.pid\r\n82079\r\n\r\n$ ps ax|grep hangaround\r\n82079 s005  S+     0:00.01 .\/hangaround 30\r\n82084 s006  R+     0:00.00 grep hangaround\r\n<\/pre>\n<p>So, the upshot is that I&#8217;m a little confused about how I&#8217;m going to create a general solution to work around this problem&#8211; a problem that doesn&#8217;t occur very often but makes FATE fail hard when it does show up.<\/p>\n<p><strong>Followup:<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/multimedia.cx\/eggs\/process-runner-redux\/\">Process Runner Redux<\/a>: Making some hard decisions regarding these problems<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to code around some PID weirdness<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,55],"tags":[],"class_list":["post-1947","post","type-post","status-publish","format-standard","hentry","category-fate-server","category-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=1947"}],"version-history":[{"count":9,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1947\/revisions"}],"predecessor-version":[{"id":4600,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1947\/revisions\/4600"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=1947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=1947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}