<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about processes)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/processes.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2023 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Tue, 18 Jul 2023 13:16:47 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Watch for new processes and list them only once</title><link>https://bgstack15.ddns.net/blog/posts/2017/06/14/watch-for-new-processes-and-list-them-only-once/</link><dc:creator>bgstack15</dc:creator><description>&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nv"&gt;true&lt;/span&gt;&lt;span class="c1"&gt;; do ps -ef | grep -iE "processname" | grep -viE "grep \-"; done | awk '!x[$10]++'&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;Discussion&lt;/h2&gt;
&lt;p&gt;Top shows everything currently running, and updates every so often (default is
2 seconds). But it has so much information for all the processes it does not
show you the details of a single entry. &lt;strong&gt;ps -ef&lt;/strong&gt; or &lt;strong&gt;ps auxe&lt;/strong&gt; only shows
you the processes at that instant. You can run that in a loop piped to grep,
but then it continues to show you the same things again and again.&lt;/p&gt;
&lt;h3&gt;Watch for new processes and list them only once&lt;/h3&gt;
&lt;p&gt;You can use this snippet to show you new entries for the process you're
looking for.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nv"&gt;true&lt;/span&gt;&lt;span class="c1"&gt;; do ps -ef | grep -iE "processname" | grep -viE "grep \-"; done | awk '!x[$10]++'&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What this does is a while loop of all the processes. It updates constantly,
because of the while true. The second grep command just prevents it from
finding the first grep statement. Piping the whole thing to the special &lt;a href="https://bgstack15.ddns.net/blog/posts/2017/04/11/remove-only-certain-duplicate-lines-with-awk/"&gt;awk
statement that removes duplicate
lines&lt;/a&gt; makes it show only unique ones. And the awk $10 is
the tenth column, which for me was the process parameter which is what I
wanted to show the uniqueness of.&lt;/p&gt;</description><category>oneliner</category><category>processes</category><category>ps</category><guid>https://bgstack15.ddns.net/blog/posts/2017/06/14/watch-for-new-processes-and-list-them-only-once/</guid><pubDate>Wed, 14 Jun 2017 13:26:24 GMT</pubDate></item></channel></rss>