<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>System Calls on Nalar</title>
    <link>https://nalar.dev/tags/system-calls/</link>
    <description>Recent content in System Calls on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 04 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/system-calls/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Avoid PID Reuse Races on Linux with pidfds</title>
      <link>https://nalar.dev/avoid-pid-reuse-races-on-linux-with-pidfds/</link>
      <pubDate>Fri, 04 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/avoid-pid-reuse-races-on-linux-with-pidfds/</guid>
      <description>&lt;p&gt;A process ID looks like an identity, but it is really a reusable number.&lt;/p&gt;&#xA;&lt;p&gt;That distinction matters in long-running supervisors, job managers, test harnesses, and other programs that observe a process and then act on it later. Between those two operations, the original process can exit and Linux can eventually reuse the same PID for an unrelated process.&lt;/p&gt;&#xA;&lt;p&gt;Traditional PID-based code can therefore have a time-of-check/time-of-use race:&lt;/p&gt;&#xA;&lt;div&#xA;  x-data=&#34;{ code: $el.querySelector(&#39;code&#39;).innerText, copied: false }&#34;&#xA;  class=&#34;code-block group relative my-6 overflow-hidden rounded-xl border border-line bg-surface-muted dark:border-night-line dark:bg-night-surface&#34;&gt;&#xA;  &lt;button&#xA;    type=&#34;button&#34;&#xA;    @click=&#34;navigator.clipboard.writeText(code); copied = true; setTimeout(() =&gt; copied = false, 1600)&#34;&#xA;    class=&#34;absolute right-3 top-3 z-10 rounded-lg border border-line-strong bg-surface px-2 py-1 font-mono text-[0.65rem] text-muted opacity-0 transition group-hover:opacity-100 hover:bg-ink hover:text-white dark:border-night-line dark:bg-night dark:text-night-muted dark:hover:bg-white dark:hover:text-ink&#34;&gt;&#xA;    &lt;span x-text=&#34;copied ? &#39;Copied&#39; : &#39;Copy&#39;&#34;&gt;&lt;/span&gt;&#xA;  &lt;/button&gt;&#xA;  &#xA;  &lt;div class=&#34;overflow-x-auto p-4 text-sm leading-6 [&amp;_pre]:!m-0 [&amp;_pre]:!bg-transparent [&amp;_pre]:!p-0 [&amp;_code]:font-mono&#34;&gt;&#xA;    &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;check PID 4242 -&amp;gt; original process exits -&amp;gt; PID 4242 is reused -&amp;gt; signal PID 4242&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&lt;p&gt;Linux PID file descriptors, usually called &lt;strong&gt;pidfds&lt;/strong&gt;, provide another model. Instead of repeatedly identifying a task by a reusable integer, a program obtains a file descriptor that refers to a particular process and can use that descriptor with pidfd-aware APIs.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Handle Linux Signals in Event Loops with signalfd</title>
      <link>https://nalar.dev/handle-linux-signals-in-event-loops-with-signalfd/</link>
      <pubDate>Fri, 04 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/handle-linux-signals-in-event-loops-with-signalfd/</guid>
      <description>&lt;p&gt;Unix signals are asynchronous by design: a signal can interrupt a program between ordinary instructions and transfer control to a signal handler. That model is useful, but it creates an awkward boundary for event-driven programs.&lt;/p&gt;&#xA;&lt;p&gt;A network server may already spend most of its time inside &lt;code&gt;poll()&lt;/code&gt;, &lt;code&gt;epoll_wait()&lt;/code&gt;, or another readiness API. Its sockets, pipes, and timers appear as file-descriptor events, while &lt;code&gt;SIGTERM&lt;/code&gt; and &lt;code&gt;SIGHUP&lt;/code&gt; arrive through a separate execution path with much stricter rules about what code may safely run.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Integrate Timers into Linux Event Loops with timerfd</title>
      <link>https://nalar.dev/integrate-timers-into-linux-event-loops-with-timerfd/</link>
      <pubDate>Fri, 04 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/integrate-timers-into-linux-event-loops-with-timerfd/</guid>
      <description>&lt;p&gt;Event loops work best when unrelated kinds of work have one common waiting mechanism. Sockets become readable. Pipes become writable. A child-process descriptor or signal descriptor can become ready. Timers are often the awkward exception.&lt;/p&gt;&#xA;&lt;p&gt;A program can call &lt;code&gt;sleep()&lt;/code&gt; or &lt;code&gt;nanosleep()&lt;/code&gt;, but that blocks the thread instead of letting it wait for I/O. It can pass a timeout to &lt;code&gt;poll()&lt;/code&gt; or &lt;code&gt;epoll_wait()&lt;/code&gt;, but one timeout becomes difficult to manage when the program has several independent deadlines. Traditional POSIX timers can deliver signals, which introduces a second asynchronous control path.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
