<p dir="auto">A common pattern with signals like SIGHUP, SIGINT, and SIGTERM is to perform some cleanup and then invoke the default handler. For example, in C:</p>
<div class="highlight highlight-source-c notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="static void signal_handler(int signum) {
    do_cleanup();
    signal(signum, SIG_DFL);
    raise(signum);
}"><pre class="notranslate"><span class="pl-k">static</span> <span class="pl-smi">void</span> <span class="pl-en">signal_handler</span>(<span class="pl-smi">int</span> <span class="pl-s1">signum</span>) {
    <span class="pl-en">do_cleanup</span>();
    <span class="pl-en">signal</span>(<span class="pl-s1">signum</span>, <span class="pl-c1">SIG_DFL</span>);
    <span class="pl-en">raise</span>(<span class="pl-s1">signum</span>);
}</pre></div>
<p dir="auto">This is different from calling <code class="notranslate">exit</code> yourself. For one thing, <code class="notranslate">exit</code> is not async-signal-safe, so you'd actually need to call <code class="notranslate">_exit</code> or <code class="notranslate">abort</code>. But more importantly, the parent process (e.g. the shell) can tell from <code class="notranslate">wait</code> if a child was killed by a signal or exited normally. So even if you mimic the exit code:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="await Deno.signal(sig);
Deno.exit(128 + sig);"><pre class="notranslate"><span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">signal</span><span class="pl-kos">(</span><span class="pl-s1">sig</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">exit</span><span class="pl-kos">(</span><span class="pl-c1">128</span> <span class="pl-c1">+</span> <span class="pl-s1">sig</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">it will not be the same as invoking the default handler.</p>
<p dir="auto">You can call <code class="notranslate">Deno.kill(Deno.pid, sig)</code>, but this requires the very broad permission <code class="notranslate">--allow-run</code>. It would be better if there was a <code class="notranslate">Deno.raise(sig)</code> function that did not require any permission.</p>
<p dir="auto">If this has already been discussed in another issue I'm sorry, I haven't found one.</p>
<p dir="auto">I'am working on cliffy and we are trying to improve the sigint handling of the prompt module, if a user hit's <code class="notranslate">ctrl+c</code>. The problem is, deno doesn't trigger the sigint signal automaticly, because we need to enable the raw mode with <code class="notranslate">Deno.setRaw</code>.</p>
<p dir="auto">Currently, the prompt module just exits if the user hit's <code class="notranslate">ctrl+c</code> by calling <code class="notranslate">Deno.exit</code>. But instead of just exiting the programm, we want to use the <code class="notranslate">Deno.kill</code> method to rise a sigint, so it's possible to run some cleanup operations if the user hit's <code class="notranslate">ctrl+c</code>.</p>
<p dir="auto">But currently it's not possible to rise a signal without the <code class="notranslate">--allow-run</code> permissions flag. And i don't want the prompt module to depend on the <code class="notranslate">--allow-run</code> flag.</p>
<p dir="auto">One option to improve this could be to allow a script to kill itself without the <code class="notranslate">--allow-run</code> flag. This could be done by checking the pid of the running script. If the pid passed to <code class="notranslate">Deno.kill</code> matches the pid of the running script, the <code class="notranslate">--allow-run</code> flag is not required.</p>