<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Gene&#39;s Blog</title>
    <subtitle>Anything that comes to mind</subtitle>
    <link href="https://blog.genemarks.net/feed.xml" rel="self" />
    <link href="https://blog.genemarks.net/" />
    <updated>2026-03-18T18:26:10.000Z</updated>
    <id>https://blog.genemarks.net/</id>
    <author>
        <name>Gene Marks</name>
        <email>mail@genemarks.net</email>
    </author>
        <entry>
            <title>Starting processes in job objects with C#</title>
            <link href="https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/" />
            <published>2026-01-28T05:00:00.000Z</published>
            <updated>2026-03-18T18:26:10.000Z</updated>
            <id>https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/</id>
            <content type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Raymond Chen wrote a helpful &lt;a href=&quot;https://devblogs.microsoft.com/oldnewthing/20230209-00/?p=107812&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;article&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; explaining the safest method of starting a process directly in a job object on Windows 10 and above. (I say &quot;safest&quot;, because it avoids a pesky race condition cleanly and effectively; but more on that later.) Working directly with the Windows API in C# is a different story. Nevertheless, it&#39;s something we must do when attempting to replicate Chen&#39;s logic.&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;creating-a-job-object&quot; tabindex=&quot;-1&quot;&gt;Creating a job object&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/#creating-a-job-object&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “Creating a job object” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;It&#39;s recommended that modern .NET apps use &lt;a href=&quot;https://github.com/microsoft/CsWin32&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;CsWin32&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; for P/Invoke support, so that&#39;s what we&#39;ll do. At this point, our &lt;code&gt;NativeMethods.txt&lt;/code&gt; only needs one entry:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CreateJobObject&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And with this method, it becomes very simple to create job objects:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; CreateJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;CreateJobObject&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;IsInvalid&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Error handling&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h4 id=&quot;as-an-aside&quot; tabindex=&quot;-1&quot;&gt;As an aside&lt;/h4&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/#as-an-aside&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “As an aside” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;You&#39;ll notice I won&#39;t take up space writing any error handling in this article. As a general WinAPI rule, when a system function fails, it will usually return &lt;code&gt;0&lt;/code&gt;. To obtain the error code and create an exception, you can do something like:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; (!&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;Win32Function&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; errorCode&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Marshal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;GetLastPInvokeError&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; win32Ex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; Win32Exception&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;errorCode&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Error handling&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With that being said, let&#39;s move on to the main course... How can we start a process &lt;em&gt;in&lt;/em&gt; our newly created job object?&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;the-gotchas-of-the-process-class&quot; tabindex=&quot;-1&quot;&gt;The gotchas of the Process class&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/#the-gotchas-of-the-process-class&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “The gotchas of the Process class” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Looking at Microsoft&#39;s &lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=net-10.0&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;documentation&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; for .NET&#39;s &lt;code&gt;Process&lt;/code&gt; class, we see many useful members. We can use a &lt;code&gt;StartInfo&lt;/code&gt; object to set characteristics of the process before starting it. We can even access the underlying OS handle with &lt;code&gt;Process.Handle&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What we &lt;em&gt;can&#39;t&lt;/em&gt; do is manipulate the process&#39;s native attribute list.&lt;/p&gt;
&lt;p&gt;You may be thinking - &quot;Can&#39;t you just start the process, obtain its handle, and use it to add the process to the job object?&quot; You can, and it might look something like:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus has-highlighted&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; Process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;StartInfo&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;FileName&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt;&quot;notepad.exe&quot;&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Race condition here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;AssignProcessToJobObject&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;jobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Handle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Though, as noted above, this method technically introduces races. A process can start and immediately exit before the next instruction is reached, in which case the &lt;code&gt;AssignProcessToJobObject&lt;/code&gt; call will certainly fail. Or a process can start and immediately spawn its own children before being added to the job object, leaving them orphaned.&lt;/p&gt;
&lt;p&gt;These possibilities are too dangerous to ignore, which is why typical methodology involves creating the process suspended, adding it to the job object, and resuming execution.&lt;/p&gt;
&lt;p&gt;As you can guess, starting processes suspended &lt;a href=&quot;https://github.com/dotnet/runtime/issues/94127&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;isn&#39;t possible with .NET&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; at the moment. You would still have to rely on more P/Invoke to replicate this technique in C#. However, on newer versions of Windows this strategy is obsolete anyway. As Chen notes, there is a modern process attribute we can take advantage of...&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;proc_thread_attribute_job_list&quot; tabindex=&quot;-1&quot;&gt;PROC_THREAD_ATTRIBUTE_JOB_LIST&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/#proc_thread_attribute_job_list&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “PROC_THREAD_ATTRIBUTE_JOB_LIST” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;According to the &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute#parameters&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Microsoft docs&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;, &lt;code&gt;PROC_THREAD_ATTRIBUTE_JOB_LIST&lt;/code&gt; is a &quot;pointer to a list of job handles to be assigned to the child process.&quot; Essentially a golden ticket for our needs (&lt;strong&gt;assuming you&#39;re using Windows 10 or later&lt;/strong&gt;). By assigning the job object to our future process&#39;s extended attribute list before it is created, we can effectively avoid &quot;hacky&quot; solutions involving process suspension altogether.&lt;/p&gt;
&lt;p&gt;To get started, we&#39;re going to need several more entries in &lt;code&gt;NativeMethods.txt&lt;/code&gt;. It should now include the following:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CloseHandle&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CreateJobObject&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CreateProcess&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;DeleteProcThreadAttributeList&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;InitializeProcThreadAttributeList&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;UpdateProcThreadAttribute&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;PROC_THREAD_ATTRIBUTE_*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;PROCESS_CREATION_FLAGS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;PROCESS_INFORMATION&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;STARTUPINFOW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;STARTUPINFOEXW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;First, I&#39;ll design a minimal wrapper class to store the process&#39;s path and handle:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; sealed&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; Process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;IDisposable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; Process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; Dispose&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;?.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;Dispose&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This class will also contain the method for actually creating the system process in a given job object. It will end up quite hefty, so I&#39;ll break it up into chunks.&lt;/p&gt;
&lt;p&gt;The first step is determining the size of the memory needed to store our process&#39;s attribute list:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; StartInJob&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nuint&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;InitializeProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;LPROC_THREAD_ATTRIBUTE_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nint&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Marshal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;AllocHGlobal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;LPROC_THREAD_ATTRIBUTE_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This initial call to &lt;code&gt;InitializeProcThreadAttributeList&lt;/code&gt; is expected to fail. Because we passed a null value as the first argument, along with the required number (1) of attributes our list will contain, Windows populated &lt;code&gt;size&lt;/code&gt; with the required buffer size. We then allocated the necessary buffer size as unmanaged memory and treated it as an attribute list.&lt;/p&gt;
&lt;p&gt;Next, we&#39;ll call the function again to initialize the list. Afterward, we can update the necessary attribute in the list with the handle to our job object:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;try&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;InitializeProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; jobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;DangerousGetHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;UpdateProcThreadAttribute&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PROC_THREAD_ATTRIBUTE_JOB_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;jobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nuint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that the attribute list is prepared, we can use it to initialize the process&#39;s startup info. We should also ensure that our process&#39;s path is the appropriate structure.&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;STARTUPINFOEXW&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;lpAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;StartupInfo&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;uint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;STARTUPINFOEXW&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;[] &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cmd&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; + &lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#EE0000;--shiki-dark:#D7BA7D&quot;&gt;&#92;0&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;ToCharArray&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Must be null terminated&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;lpCommandLine&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cmd&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because &lt;code&gt;PROC_THREAD_ATTRIBUTE_JOB_LIST&lt;/code&gt; is an extended attribute, we needed to use a &lt;code&gt;STARTUPINFOEX&lt;/code&gt; structure. It&#39;s essentially a wrapper for &lt;code&gt;STARTUPINFO&lt;/code&gt; along with the attribute list for the process.&lt;/p&gt;
&lt;p&gt;Additionally, as per the &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-startupinfoexa#remarks&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Microsoft docs&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;, the &lt;code&gt;cb&lt;/code&gt; member of &lt;code&gt;STARTUPINFOEX.StartupInfo&lt;/code&gt; &lt;em&gt;must&lt;/em&gt; be assigned the size of its wrapping structure when using an extended startup info structure.&lt;/p&gt;
&lt;p&gt;At this point, we can finally create the process:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;PROCESS_INFORMATION&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;CreateProcess&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; lpCommandLine&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PROCESS_CREATION_FLAGS&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;EXTENDED_STARTUPINFO_PRESENT&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;StartupInfo&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;out&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa#parameters&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;another requirement&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; of using extended attributes is that &lt;code&gt;EXTENDED_STARTUPINFO_PRESENT&lt;/code&gt; &lt;em&gt;must&lt;/em&gt; be specified in the &lt;code&gt;dwCreationFlags&lt;/code&gt; parameter of our &lt;code&gt;CreateProcess&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;In the above code block, I&#39;ve declared &lt;code&gt;pi&lt;/code&gt; explicitly for clarity. We&#39;re now going to use it to obtain a handle to the newly created process. Afterward, we&#39;ll write some final necessary cleanup.&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;hProcess&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;ownsHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Not using this. Handle must be closed.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;CloseHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;hThread&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;finally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;DeleteProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Marshal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;FreeHGlobal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By passing &lt;code&gt;true&lt;/code&gt; to the &lt;code&gt;ownsHandle&lt;/code&gt; parameter, we relinquished ownership of the process handle and responsibility of its lifetime. At this point, our custom &lt;code&gt;Process&lt;/code&gt; object will finally own a safe handle to the system process. When &lt;code&gt;Dispose()&lt;/code&gt; is called on &lt;code&gt;SafeHandle&lt;/code&gt;, .NET will take care of closing the system handle for us.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;hThread&lt;/code&gt;, however, is a handle we have no plans of using. Technically, &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-process_information#remarks&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;it will be closed&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; by the system when its parent process terminates. Though it is still more responsible to expressly call the &lt;code&gt;CloseHandle&lt;/code&gt; function, as seen above.&lt;/p&gt;
&lt;p&gt;Lastly, it&#39;s vital not to forget about the attribute list and the unmanaged memory we allocated for it earlier.&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;the-complete-package&quot; tabindex=&quot;-1&quot;&gt;The complete package&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2026-01-28-starting-processes-in-job-objects-with-csharp/#the-complete-package&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “The complete package” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;It took awhile, but we&#39;ve now constructed a custom solution that can start a system process in a given job object. Putting the whole thing together, it looks like this:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; sealed&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; Process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; : &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;IDisposable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; Process&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; unsafe&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; StartInJob&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nuint&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;InitializeProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;LPROC_THREAD_ATTRIBUTE_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nint&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Marshal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;AllocHGlobal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;LPROC_THREAD_ATTRIBUTE_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;try&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;InitializeProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; jobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;safeJobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;DangerousGetHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;UpdateProcThreadAttribute&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PROC_THREAD_ATTRIBUTE_JOB_LIST&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;jobHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;nuint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;HANDLE&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;STARTUPINFOEXW&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;lpAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;StartupInfo&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;uint&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;sizeof&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;STARTUPINFOEXW&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;[] &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cmd&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = (&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; + &lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#EE0000;--shiki-dark:#D7BA7D&quot;&gt;&#92;0&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;ToCharArray&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Must be null terminated&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;lpCommandLine&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;cmd&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt;PROCESS_INFORMATION&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;CreateProcess&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; lpCommandLine&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PROCESS_CREATION_FLAGS&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;EXTENDED_STARTUPINFO_PRESENT&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; siex&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;StartupInfo&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;out&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt; pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#267F99;--shiki-dark:#4EC9B0&quot;&gt; SafeFileHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;hProcess&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;ownsHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 4ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 6ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 8ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 10ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#008000;--shiki-dark:#6A9955&quot;&gt;// Not using this. Handle must be closed.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;CloseHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;pi&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;hThread&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#AF00DB;--shiki-dark:#C586C0&quot;&gt;finally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;PInvoke&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;DeleteProcThreadAttributeList&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;list&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;Marshal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;FreeHGlobal&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;listBuffer&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 0ch;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;indent&quot; style=&quot;--indent-offset: 2ch;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt; Dispose&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;?.&lt;/span&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;Dispose&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#001080;--shiki-dark:#9CDCFE&quot;&gt;SafeHandle&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;indent&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next steps in extending the class might include adding an &quot;exited&quot; event handler using a wait handle, but that&#39;s for another post.&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;</content>
        </entry>
        <entry>
            <title>A poem on software bloat</title>
            <link href="https://blog.genemarks.net/blog/2025-11-18-a-poem-on-software-bloat/" />
            <published>2025-11-18T05:00:00.000Z</published>
            <updated>2026-03-18T18:26:10.000Z</updated>
            <id>https://blog.genemarks.net/blog/2025-11-18-a-poem-on-software-bloat/</id>
            <content type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;bloat&quot; tabindex=&quot;-1&quot;&gt;Bloat&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-11-18-a-poem-on-software-bloat/#bloat&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “Bloat” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Bloat is real, bloat is fake.&lt;br&gt;
A giraffe has four &lt;s&gt;stomachs&lt;/s&gt; &lt;s&gt;compartments&lt;/s&gt;.&lt;/p&gt;
&lt;p&gt;Bloat is palpable, bloat is abstract.&lt;br&gt;
A 64 KB binary &lt;s&gt;is&lt;/s&gt; &lt;s&gt;not&lt;/s&gt; bloat.&lt;/p&gt;
&lt;p&gt;01000010 01101100 01101111 01100001 01110100&lt;br&gt;
is &lt;s&gt;more&lt;/s&gt; &lt;s&gt;less&lt;/s&gt; than&lt;br&gt;
42 6C 6F 61 74.&lt;/p&gt;
&lt;p&gt;Bloat is unbearable, bloat is liberating.&lt;br&gt;
This &lt;s&gt;is&lt;/s&gt; &lt;s&gt;not&lt;/s&gt; bloat.&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;</content>
        </entry>
        <entry>
            <title>Jellyfin and mergerfs in Proxmox</title>
            <link href="https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/" />
            <published>2025-02-10T05:00:00.000Z</published>
            <updated>2026-03-18T18:26:10.000Z</updated>
            <id>https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/</id>
            <content type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;&lt;mark&gt;This is not a tutorial for setting up Jellyfin itself.&lt;/mark&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/trapexit/mergerfs&quot;&gt;&lt;img src=&quot;https://blog.genemarks.net/uploads/mergerfs.png&quot; alt=&quot;mergerfs github&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As someone who has used Jellyfin pretty much since the initial Emby fork, I&#39;ve had many years to tweak and optimize parts of my setup. After several iterations, my current configuration has been the longest serving and stablest by far.&lt;/p&gt;
&lt;p&gt;One of its core components being &lt;a href=&quot;https://trapexit.github.io/mergerfs/latest/&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;mergerfs&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;what-is-mergerfs%3F&quot; tabindex=&quot;-1&quot;&gt;What is mergerfs?&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#what-is-mergerfs%3F&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “What is mergerfs?” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;mergerfs is a FUSE based union filesystem geared towards simplifying storage and management of files across numerous commodity storage devices. It is similar to mhddfs, unionfs, and aufs.
&lt;cite&gt;&lt;a href=&quot;https://github.com/trapexit/mergerfs&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;trapexit/mergerfs&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If just one thing is taken away, let it be &quot;union filesystem.&quot; Essentially, mergerfs lets you pool multiple directories or filesystems into a single mount point. There are many reasons you might want to achieve this, but my use case is for serving media and metadata for Jellyfin together efficiently.&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;a-top-down-view&quot; tabindex=&quot;-1&quot;&gt;A top-down view&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#a-top-down-view&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “A top-down view” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;More specifically, the media itself, located on a NAS, is mounted as an SMB share on the Proxmox host. This share is passed to the Jellyfin container as a R/O mount point. The metadata - including .nfo&#39;s, images, and subtitles - are located directly in the container.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://blog.genemarks.net/uploads/mermaid/jellyfin-mergerfs-proxmox.svg&quot; alt=&quot;Proxmox with mergerfs flow chart&quot;&gt;&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;why-merge-these-directories%3F&quot; tabindex=&quot;-1&quot;&gt;Why merge these directories?&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#why-merge-these-directories%3F&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “Why merge these directories?” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;While I&#39;ve always preferred the concept of keeping metadata next to my media files, two deal breakers have deterred me:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: The media share accessed by Jellyfin must be read-only. I don&#39;t want the container to have any means to delete or alter data on my NAS. Of course, this means Jellyfin wouldn&#39;t be able to create or modify metadata next to the media.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Even if I work around the security issue, serving metadata alongside the media on mechanical hard drives could be a bit... clunky.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Using mergerfs provides a solution that is...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Secure&lt;/strong&gt;: Messing with media files through the container is prohibited, but metadata manipulation is still allowed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Speedy&lt;/strong&gt;&lt;sup class=&quot;footnote-ref&quot;&gt;&lt;a href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#fn1&quot; id=&quot;fnref1&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;[1]&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/sup&gt;: Artwork and other metadata is served to clients much quicker on the host NVME than if they were located on the NAS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organized&lt;/strong&gt;: The metadata folder structure mirrors what I&#39;m used to.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexible&lt;/strong&gt;: Kodi, Plex, Jellyfin, and Emby should all recognize my collection properly via the merged mount.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h3 id=&quot;the-setup&quot; tabindex=&quot;-1&quot;&gt;The Setup&lt;/h3&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#the-setup&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “The Setup” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Keep in mind that for this setup, I&#39;ll be using my actual directories, so be sure to change them wherever appropriate.&lt;/p&gt;
&lt;p&gt;The first piece in this equation is making sure the media share is available in the LXC. The simplest way to achieve this is by first mounting it on the Proxmox host itself.&lt;/p&gt;
&lt;p&gt;Here&#39;s the line in my host&#39;s &lt;code&gt;fstab&lt;/code&gt; that accomplishes that:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;//nas/Media /mnt/lxc_shares/media cifs vers=3.0,_netdev,x-systemd.automount,noatime,uid=100000,gid=110000,dir_mode=0770,file_mode=0770,credentials=/etc/.smb-cred-media,defaults 0 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Permission-wise, this line provides a couple of ways for container users to access the share. First, the &lt;code&gt;root&lt;/code&gt; user of an unprivileged LXC has full access. In addition, LXC users that are added to the group &lt;code&gt;110000&lt;/code&gt; have full access. (Thanks &lt;a href=&quot;https://github.com/JamesTurland/JimsGarage/tree/main/LXC/NAS&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;@jims-garage&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;Since the SMB credentials are stored in a separate file, they need to be secured by executing:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; chown&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; root:root&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; /etc/.smb-cred-media&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color:#098658;--shiki-dark:#B5CEA8&quot;&gt; 600&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; /etc/.smb-cred-media&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, the unprivileged Jellyfin container is given access to the host mount by adding the following line to its &lt;code&gt;/etc/pve/lxc/{lxc_id}.conf&lt;/code&gt; config file:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;mp0: /mnt/lxc_shares/media/,mp=/mnt/media,ro=1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the &lt;code&gt;ro=1&lt;/code&gt; setting that ensures the mount point is read-only.&lt;/p&gt;
&lt;p&gt;After a quick reboot, a read-only &lt;code&gt;/mnt/media&lt;/code&gt; mount point should pop up on the Jellyfin container.&lt;/p&gt;
&lt;div class=&quot;anchor-heading&quot;&gt;
&lt;h4 id=&quot;the-merge&quot; tabindex=&quot;-1&quot;&gt;The merge&lt;/h4&gt;
&lt;a class=&quot;anchor external&quot; href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#the-merge&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;Permalink to “The merge” #&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;It&#39;s important to first understand the layout of the directories involved in the merge. Here is a sample from my media mount:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus has-highlighted&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/mnt/media/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;├─ Movies/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  ├─ A Goofy Movie (1995) [imdbid-tt0113198]/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].mkv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ trailer.mkv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and another matching sample of the meta folder located directly on the LXC:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus has-highlighted&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/srv/docker-data/jellyfin/meta/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;├─ Movies/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  ├─ A Goofy Movie (1995) [imdbid-tt0113198]/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].nfo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].en.srt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ backdrop.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ folder.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ landscape.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span&gt;│  │  ├─ logo.png&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, the directories are perfectly mirrored, yet serve different content. The final merged directory consists of all of the content from both original directory trees.&lt;/p&gt;
&lt;p&gt;With that, let&#39;s move on to the mergerfs configuration.&lt;/p&gt;
&lt;p&gt;On Debian or Ubuntu, mergerfs can be installed using:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; apt&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; update&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; apt&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; mergerfs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After installation, really the only configuration is to modify the container&#39;s &lt;code&gt;fstab&lt;/code&gt;. I&#39;ve added the following line to mine:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/srv/docker-data/jellyfin/meta:/mnt/media /srv/docker-data/jellyfin/media fuse.mergerfs defaults,allow_other,use_ino,category.create=epmfs 0 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Take note of the option &lt;code&gt;allow_other&lt;/code&gt; at the end of the line, which ensures that users other than the mount-er have access to the merged directory.&lt;/p&gt;
&lt;p&gt;After saving the &lt;code&gt;fstab&lt;/code&gt;, the merged directory can be created and mounted via&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; mkdir&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; /srv/docker-data/jellyfin/media&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#795E26;--shiki-dark:#DCDCAA&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color:#A31515;--shiki-dark:#CE9178&quot;&gt; mount&lt;/span&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt; -a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;leaving the final merged directory looking like this:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/srv/docker-data/jellyfin/media/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;├─ Movies/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  ├─ A Goofy Movie (1995) [imdbid-tt0113198]/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].mkv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].nfo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ A Goofy Movie (1995) [imdbid-tt0113198].en.srt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ backdrop.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ folder.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ landscape.jpg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ logo.png&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;│  │  ├─ trailer.mkv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because I use Docker for Jellyfin, I also edited its service file with &lt;code&gt;systemctl edit docker&lt;/code&gt; to ensure Docker only starts after the merged directory is accessible:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes light-plus dark-plus&quot; style=&quot;background-color:#FFFFFF;--shiki-dark-bg:#1E1E1E;color:#000000;--shiki-dark:#D4D4D4&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;[Unit]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;RequiresMountsFor&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;=/srv/docker-data/jellyfin/media&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#0000FF;--shiki-dark:#569CD6&quot;&gt;After&lt;/span&gt;&lt;span style=&quot;color:#000000;--shiki-dark:#D4D4D4&quot;&gt;=local-fs.target&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&#39;s pretty much all there is to it! All media is imported into Jellyfin through the merged directory. With &lt;em&gt;NFO&lt;/em&gt; selected as the metadata saver and &lt;em&gt;Save artwork into media folders&lt;/em&gt; enabled, Jellyfin will write metadata files to &lt;code&gt;/srv/docker-data/jellyfin/meta/&lt;/code&gt; through the merged directory.&lt;sup class=&quot;footnote-ref&quot;&gt;&lt;a href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#fn2&quot; id=&quot;fnref2&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;[2]&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;hr class=&quot;footnotes-sep&quot;&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn1&quot; class=&quot;footnote-item&quot;&gt;&lt;p&gt;mergerfs is &lt;a href=&quot;https://en.wikipedia.org/wiki/Filesystem_in_Userspace&quot; class=&quot;external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;FUSE&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt; based. User-space filesystem implementations can struggle to match the speed of traditional kernel-space due to all the context switches and sys calls in the chain of operations. &lt;em&gt;Could&lt;/em&gt; this setup be more efficient? In theory.&lt;/p&gt;
&lt;p&gt;But to put it bluntly, I don&#39;t find the idea of making a container privileged &lt;em&gt;just&lt;/em&gt; to chase hypothetical performance gains really necessary. &lt;a href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#fnref1&quot; class=&quot;footnote-backref external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;↩︎&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&quot;fn2&quot; class=&quot;footnote-item&quot;&gt;&lt;p&gt;When adding media, a skeleton of the media&#39;s folder structure must be present in the meta directory before importing to Jellyfin. &lt;a href=&quot;https://blog.genemarks.net/blog/2025-02-10-jellyfin-and-mergerfs-in-proxmox/#fnref2&quot; class=&quot;footnote-backref external&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;&lt;span&gt;↩︎&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;12&quot; height=&quot;12&quot; viewBox=&quot;0 0 12 12&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M6 1h5v5L8.86 3.85 4.7 8 4 7.3l4.15-4.16L6 1ZM2 3h2v1H2v6h6V8h1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
&lt;/body&gt;&lt;/html&gt;</content>
        </entry>
</feed>
