<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>not sure I got right what is the issue and what would be a
      solution for it, but maybe you can leverage evrexec to create a
      child process and by that keep it in kamailio children list.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 13.09.22 19:15, Marat Gareev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAGBFc1Xr0ZGe4m9otN3-RwEeFzXZ51RNjXyZa2hP9r977g=yPw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hello!
        <div><br>
        </div>
        <div>I'm trying to use app_python module to perform periodic
          actions.</div>
        <div><br>
        </div>
        <div>This is a simple python code</div>
        <div>
          <div style="color:rgb(51,51,51);background-color:rgb(245,245,245);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">_update</span><span style="color:rgb(119,119,119)">():</span></div><div>    <span style="color:rgb(75,105,198)">while</span> <span style="color:rgb(156,93,39)">True</span><span style="color:rgb(119,119,119)">:</span></div><div><span style="color:rgb(119,119,119)">        </span>_action<span style="color:rgb(119,119,119)">()</span></div><div>        time<span style="color:rgb(119,119,119)">.</span>sleep<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">60</span><span style="color:rgb(119,119,119)">)</span></div>
<div><span style="color:rgb(122,62,157)">class</span> <span style="color:rgb(122,62,157);font-weight:bold">noop_handler</span><span style="color:rgb(119,119,119)">:</span></div><div>    <span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">child_init</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">self</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(122,62,157)">rank</span><span style="color:rgb(119,119,119)">):</span></div><div>        <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(156,93,39)">0</span></div>
<div>    <span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">ksr_request_route</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">self</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(122,62,157)">msg</span><span style="color:rgb(119,119,119)">):</span></div><div>        <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(156,93,39)">1</span></div>
<div><span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">mod_init</span><span style="color:rgb(119,119,119)">():</span></div><div>    <span style="color:rgb(170,170,170);font-style:italic"># signal.signal(signal.SIGTERM, signal.default_int_handler)</span></div><div>    <span style="color:rgb(122,62,157)">proc</span> <span style="color:rgb(119,119,119)">=</span> multiprocessing<span style="color:rgb(119,119,119)">.</span>Process<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">target</span><span style="color:rgb(119,119,119)">=</span><span style="color:rgb(170,55,49);font-weight:bold">_update</span><span style="color:rgb(119,119,119)">)</span></div><div>    <span style="color:rgb(170,170,170);font-style:italic"># proc.daemon = True</span></div><div>    <span style="color:rgb(122,62,157)">proc</span><span style="color:rgb(119,119,119)">.</span>start<span style="color:rgb(119,119,119)">()</span></div><div>    ksr<span style="color:rgb(119,119,119)">.</span>notice<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(119,119,119)">'</span><span style="color:rgb(68,140,39)">Forked process </span><span style="color:rgb(156,93,39)">{}</span><span style="color:rgb(68,140,39)"> to update</span><span style="color:rgb(119,119,119)">\n'</span><span style="color:rgb(119,119,119)">.</span><span style="color:rgb(170,55,49);font-weight:bold">format</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">proc</span><span style="color:rgb(119,119,119)">.</span>pid<span style="color:rgb(119,119,119)">))</span></div><div>    <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(122,62,157);font-weight:bold">noop_handler</span><span style="color:rgb(119,119,119)">()</span></div></div>
        </div>
        <div><br>
        </div>
        <div>After killing kamailio processes with SIGTERM signal (<span style="background-color:rgb(245,245,245);color:rgb(51,51,51);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre">killall kamailio</span>)
          I see zombie process.</div>
        <div>And if I try to process the signal in daemon mode (see the
          comments in the snippet above), I get critical errors in the
          logs and still see processes:</div>
        <div>
          <div style="color:rgb(51,51,51);background-color:rgb(245,245,245);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">NOTICE</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>kemi<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">124</span><span style="color:rgb(119,119,119)">]:</span> sr_kemi_core_notice<span style="color:rgb(119,119,119)">():</span> Forked process <span style="color:rgb(156,93,39)">37002</span> to update</div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div><div>Process Process<span style="color:rgb(119,119,119)">-</span><span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">:</span></div><div>Traceback <span style="color:rgb(119,119,119)">(</span>most recent call last<span style="color:rgb(119,119,119)">):</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/usr/lib64/python2.7/multiprocessing/process.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">258</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> _bootstrap</div><div>    <span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>run<span style="color:rgb(119,119,119)">()</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/usr/lib64/python2.7/multiprocessing/process.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">114</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> run</div><div>    <span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_target<span style="color:rgb(119,119,119)">(*</span><span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_args<span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">**</span><span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_kwargs<span style="color:rgb(119,119,119)">)</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/tmp/script.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">155</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> _update</div><div>    time<span style="color:rgb(119,119,119)">.</span>sleep<span style="color:rgb(119,119,119)">(</span>period<span style="color:rgb(119,119,119)">)</span></div><div><span style="color:rgb(122,62,157)">KeyboardInterrupt</span></div><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ALERT</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>main<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">774</span><span style="color:rgb(119,119,119)">]:</span> handle_sigs<span style="color:rgb(119,119,119)">():</span> child process <span style="color:rgb(156,93,39)">37002</span> exited normally<span style="color:rgb(119,119,119)">,</span> status<span style="color:rgb(119,119,119)">=</span><span style="color:rgb(156,93,39)">1</span></div><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">INFO</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>main<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">802</span><span style="color:rgb(119,119,119)">]:</span> handle_sigs<span style="color:rgb(119,119,119)">():</span> terminating due to <span style="color:rgb(156,93,39)">SIGCHLD</span></div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div><div> <span style="color:rgb(156,93,39)">8</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37014</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">CRITICAL</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>pass_fd<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">277</span><span style="color:rgb(119,119,119)">]:</span> receive_fd<span style="color:rgb(119,119,119)">():</span> <span style="color:rgb(156,93,39)">EOF</span> on <span style="color:rgb(156,93,39)">4</span></div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div></div>
        </div>
        <div><br>
        </div>
        <div>So, how I can kill child process by SIGTERM signal?</div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a></pre>
  </body>
</html>