snipt

Ctrl+h for KB shortcuts

Bash

kill process that contains string but not another string

1
2
3
4
5
# command line:
$ pgrep -lf "spork" | grep -v "tmux" | awk '{print $1}' | xargs kill -9

# via yaml or environment hostile to special characters (e.g., tmuxinator config)
$ kill -9 $(pgrep -lf "rails s" | grep -v "tmux" | cut -d " " -f1); rails s
https://snipt.net/embed/f78fdc50c4bf053db181c85adfb124ea/
https://snipt.net/raw/f78fdc50c4bf053db181c85adfb124ea/
f78fdc50c4bf053db181c85adfb124ea
bash
Bash
6
2016-09-29T02:12:27
True
False
False
Apr 11, 2013 at 12:51 AM
/api/public/snipt/56301/
kill-process-that-contains-string-but-not-another-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># command line:</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$ </span>pgrep -lf <span class="s2">&quot;spork&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> awk <span class="s1">&#39;{print $1}&#39;</span> <span class="p">|</span> xargs <span class="nb">kill</span> -9 </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># via yaml or environment hostile to special characters (e.g., tmuxinator config)</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$ </span><span class="nb">kill</span> -9 <span class="k">$(</span>pgrep -lf <span class="s2">&quot;rails s&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> cut -d <span class="s2">&quot; &quot;</span> -f1<span class="k">)</span><span class="p">;</span> rails s </span></pre></div> </td></tr></table>
awk, cut, grep, kill, linux, pgrep, process, rails, server, spork, tmux, tmuxinator, ubuntu, xargs

Bash

kill process by name

$ pkill -f spork
https://snipt.net/embed/508550e85aa10394dbe0bfa92c619c59/
https://snipt.net/raw/508550e85aa10394dbe0bfa92c619c59/
508550e85aa10394dbe0bfa92c619c59
bash
Bash
1
2016-09-29T07:28:32
True
False
False
/api/public/snipt/56295/
kill-process-by-name
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nv">$ </span>pkill -f spork </span></pre></div> </td></tr></table>
kill, linux, process

Bash

kill process specified in pid file

$ kill -9 $(<tmp/pids/server.pid); rails s
https://snipt.net/embed/7d9a4935c5a281c68714a9154fcc1490/
https://snipt.net/raw/7d9a4935c5a281c68714a9154fcc1490/
7d9a4935c5a281c68714a9154fcc1490
bash
Bash
1
2016-09-22T11:20:52
True
False
False
/api/public/snipt/56294/
kill-process-specified-in-pid-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nv">$ </span><span class="nb">kill</span> -9 <span class="k">$(</span>&lt;tmp/pids/server.pid<span class="k">)</span><span class="p">;</span> rails s </span></pre></div> </td></tr></table>
kill, linux, pid, process
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.