TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Taming non-terminating Bash processes

16 pointsby pstadlerover 10 years ago

3 comments

fensipensover 10 years ago
Sorry Pädu but this smells for many reasons.. first:<p><pre><code> The dns-sd command is primarily intended for interactive use. Because its command-line arguments and output format are subject to change, invoking it from a shell script will generally be fragile. Additionally, the asynchronous nature of DNS Service Discovery does not lend itself easily to script-oriented programming. For example, calls like &quot;browse&quot; never complete; </code></pre> Second, &quot;SIGKILL is too verbose, SIGINT is too soft&quot;.. how about SIGTERM? Its very likely that you&#x27;re doing it wrong if you need to use -KILL in your scripts.<p>Third, &quot;[1] 58181 killed .&#x2F;discover-vnc.sh --- It&#x27;s crucial to suppress this line.&quot; again, if you think you must suppress this, you&#x27;re doing it wrong. This shouldn&#x27;t pop up in the first place.<p>Fourth, what about fifos and `$!&#x27;?<p>Fifth, why bash? Use the sh-subset.<p>etc.<p>It&#x27;s cute that you managed to solve your problem but this is nothing more than an unreliable hack, pompously presented (&quot;Taming non-terminating Bash processes&quot;, &quot;Kill the children&quot;..)
评论 #8578139 未加载
ttwwmmover 10 years ago
The use of &lt;(..) is really weird here... why not just pipe dns-sd to the while loop?<p><pre><code> dns-sd | while read -r line ; do ... done </code></pre> Sure, you won&#x27;t be able to accumulate the output for the trap, but you shouldn&#x27;t <i>need</i> to---this is stream processing!<p>Consider replacing the while loop with awk. This sort of thing is exactly what awk is good at:<p><pre><code> BEGIN { FS = &quot; &quot;; count = 0; } NR &gt; 5 { count++ print if ($3 != &quot;3&quot;) { exit; } } END { printf(&quot;%d hosts found\n&quot;, count); } </code></pre> You could also do it with GNU sed (you&#x27;ll need the q or Q command for early exit, and that&#x27;s a GNU extension---no idea if it&#x27;s available on OS X).
评论 #8578202 未加载
fragmedeover 10 years ago
That&#x27;s all well and good, but the real issue is that dns-sd is really meant to be used from a shell script<i>.<p>It should be noted that Linux&#x27;s command line program to enumerate network services, avahi-browse, includes a &#x27;-t&#x27; flag so that terminates after dumping service entries.<p></i><a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/dns-sd.1.html" rel="nofollow">https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;mac&#x2F;documentation&#x2F;Darwin...</a>
评论 #8579008 未加载