<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Perl on Xi's Blog</title><link>https://xichen1997.github.io/tags/perl/</link><description>Recent content in Perl on Xi's Blog</description><generator>Hugo -- 0.154.5</generator><language>en-us</language><lastBuildDate>Tue, 21 Nov 2023 21:05:14 -0400</lastBuildDate><atom:link href="https://xichen1997.github.io/tags/perl/index.xml" rel="self" type="application/rss+xml"/><item><title>The lessons I learned from setting up an API server via perl script</title><link>https://xichen1997.github.io/posts/2023-11-21-the-lessons-i-learned-from-setting-up-an-api-server-via-perl-script/</link><pubDate>Tue, 21 Nov 2023 21:05:14 -0400</pubDate><guid>https://xichen1997.github.io/posts/2023-11-21-the-lessons-i-learned-from-setting-up-an-api-server-via-perl-script/</guid><description>&lt;h2 id="problem-statement"&gt;Problem Statement&lt;/h2&gt;
&lt;p&gt;Recently When I was trying to set up an API server in a perl script to do some unit tests, I met lots of trouble.&lt;/p&gt;
&lt;p&gt;In conclusion, the trouble can be classfied as 3 parts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The residual server processes can&amp;rsquo;t be killed properly.&lt;/li&gt;
&lt;li&gt;Program stucked after launch the API server.&lt;/li&gt;
&lt;li&gt;stdin, stdout, stderr on windows.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="error-examples"&gt;Error examples&lt;/h2&gt;
&lt;h3 id="the-residual-server-processes-cant-be-killed"&gt;The residual server processes can&amp;rsquo;t be killed.&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-perl" data-lang="perl"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;perl&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pl&lt;/span&gt; &lt;span class="n"&gt;daemon&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="n"&gt;http:&lt;/span&gt;&lt;span class="sr"&gt;//&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Use the command above in main test script will launch an API server in a child process. The residual server processes should be killed without any left after the tests. At first I use &amp;ldquo;system&amp;rdquo; to run the command, and then kill it in a different system command via:&lt;/p&gt;</description></item></channel></rss>