<div dir="auto">Pipelines somewhat rely on the kernel delivering SIGPIPE to the writer as soon as the read end is closed. So if you have `foo | head -1`, then as soon as head reads enough and exits, foo gets killed via SIGPIPE. But as most systemd-managed services aren't shell interpreters, systemd marks SIGPIPE as "ignored" when starting the service process, so that if the service is somehow tricked into opening a pipe that a user has mkfifo'd, at least the kernel can't be tricked into killing the service. You can opt out of this using IgnoreSIGPIPE=.<div dir="auto"><div dir="auto"><div dir="auto"><br></div><div dir="auto">(Though even if there's no signal, I believe the writer should also get an -EPIPE out of every write attempt, but not all tools pay attention to it – some just completely ignore the write() result, like apparently `fold` does in your case...)<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 19, 2022, 20:18 Brian Reichert <<a href="mailto:reichert@numachi.com" target="_blank" rel="noreferrer">reichert@numachi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I apologize for the vague subject.<br>
<br>
The background: I've inherited some legacy software to manage.<br>
<br>
This is on SLES12 SP5, running:<br>
<br>
systemd-228-157.40.1.x86_64<br>
<br>
One element is a systemd-managed service, written in Perl, that in<br>
turn, is using bash to generate random numbers (don't ask me why<br>
this tactic was adopted).<br>
<br>
Here's an isolation of that logic:<br>
<br>
pheonix:~ # cat /root/<a href="http://random_str.pl" rel="noreferrer noreferrer noreferrer" target="_blank">random_str.pl</a><br>
#!/usr/bin/perl<br>
print "$0 start ".time."\n";<br>
my $randStr = `cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 64|head -1`;<br>
print "$0 end ".time."\n";<br>
<br>
You can run this from the command-line, to see how quickly it<br>
nominally operates.<br>
<br>
What I can reproduce in my environment, very reliably, is that when<br>
this is invoked as a service:<br>
<br>
- the 'head' command exits very quickly (to be expected)<br>
- the shell does not exit (maybe missed a SIGCHILD?)<br>
- 'fold' chews a CPU core<br>
- A kernel trace shows that 'fold' is spinning on SIGPIPEs, as it's<br>
STDOUT is no longer connected to another process.<br>
<br>
My service unit:<br>
<br>
pheonix:~ # cat /etc/systemd/system/random_str.service<br>
[Unit]<br>
Description=gernate random number<br>
After=network.target local-fs.target<br>
<br>
[Service]<br>
Type=oneshot<br>
RemainAfterExit=yes<br>
ExecStart=/root/<a href="http://random_str.pl" rel="noreferrer noreferrer noreferrer" target="_blank">random_str.pl</a><br>
ExecStop=/usr/bin/true<br>
#TimeoutSec=infinity<br>
TimeoutSec=900<br>
<br>
[Install]<br>
WantedBy=multi-user.target<br>
<br>
Easy to repro; this hangs forever, instead of exiting quickly.<br>
<br>
pheonix:~ # systemctl daemon-reload<br>
pheonix:~ # systemctl start random_str<br>
<br>
Let me know if there are any other details of my environment that<br>
would be helpful here.<br>
<br>
-- <br>
Brian Reichert <<a href="mailto:reichert@numachi.com" rel="noreferrer noreferrer" target="_blank">reichert@numachi.com</a>><br>
BSD admin/developer at large <br>
</blockquote></div>