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

run a process and echo its process id

$  spork & echo $! > tmp/pids/spork.pid
https://snipt.net/embed/afbac0b76aac0ef49bd9293b2fd999ad/
https://snipt.net/raw/afbac0b76aac0ef49bd9293b2fd999ad/
afbac0b76aac0ef49bd9293b2fd999ad
bash
Bash
1
2016-09-30T08:47:35
True
False
False
/api/public/snipt/56296/
run-a-process-and-echo-its-process-id
<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> spork <span class="p">&amp;</span> <span class="nb">echo</span> <span class="nv">$!</span> &gt; tmp/pids/spork.pid </span></pre></div> </td></tr></table>
bash, process, ubuntu

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

Bash

Search zombie process in linux with awk or without awk

1
2
3
4
5
#more effective, using awk
ps aux | awk '{ print $8 " " $2 }' | grep -w Z

#less effective, without awk
ps -el | grep 'Z'
https://snipt.net/embed/3bc0b112edf34393e223f18bd9b6d361/
https://snipt.net/raw/3bc0b112edf34393e223f18bd9b6d361/
3bc0b112edf34393e223f18bd9b6d361
bash
Bash
5
2016-09-30T08:32:00
True
False
False
/api/public/snipt/45495/
search-zombie-process-in-linux-with-awk-or-without-awk
<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">#more effective, using awk</span> </span><span id="L-2"><a name="L-2"></a>ps aux <span class="p">|</span> awk <span class="s1">&#39;{ print $8 &quot; &quot; $2 }&#39;</span> <span class="p">|</span> grep -w Z </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c">#less effective, without awk</span> </span><span id="L-5"><a name="L-5"></a>ps -el <span class="p">|</span> grep <span class="s1">&#39;Z&#39;</span> </span></pre></div> </td></tr></table>
"search zombie process", awk, bash, linux, process, sh, zombie

Bash

mysql process list

mysqladmin -p processlist
https://snipt.net/embed/a31ac783f3d779ab197b4d1a15564b79/
https://snipt.net/raw/a31ac783f3d779ab197b4d1a15564b79/
a31ac783f3d779ab197b4d1a15564b79
bash
Bash
1
2016-09-30T11:17:09
True
False
False
/api/public/snipt/11525/
mysql-process-list
<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>mysqladmin -p processlist </span></pre></div> </td></tr></table>
list, mysql, process

Bash

top twenty processes by memory

ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | head -21
https://snipt.net/embed/5a3749c4745db29b0bf5170ba77f7b9c/
https://snipt.net/raw/5a3749c4745db29b0bf5170ba77f7b9c/
5a3749c4745db29b0bf5170ba77f7b9c
bash
Bash
1
2016-09-30T16:09:20
True
False
False
/api/public/snipt/8988/
top-twenty-processes-by-memory
<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>ps -eo pmem,pcpu,rss,vsize,args <span class="p">|</span> sort -k <span class="m">1</span> -r <span class="p">|</span> head -21 </span></pre></div> </td></tr></table>
bash, memory, monitoring, process, server
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.