Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

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-12-04T05:28:12
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></span><span id="L-1"><a name="L-1"></a><span class="c1"># command line:</span> </span><span id="L-2"><a name="L-2"></a>$ 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="c1"># 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="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-12-07T20:50:04
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></span><span id="L-1"><a name="L-1"></a>$ 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-12-04T06:33:01
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></span><span id="L-1"><a name="L-1"></a>$ 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-12-04T20:15:21
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></span><span id="L-1"><a name="L-1"></a>$ <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-12-10T01:23:02
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></span><span id="L-1"><a name="L-1"></a><span class="c1">#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="c1">#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-12-08T04:51:01
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></span><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-12-08T04:51:28
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></span><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 [email protected].