{"id":156,"date":"2011-04-20T21:30:12","date_gmt":"2011-04-20T21:30:12","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=156"},"modified":"2011-04-21T02:17:34","modified_gmt":"2011-04-21T02:17:34","slug":"aliases-to-kill-linux-processes","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2011\/04\/20\/aliases-to-kill-linux-processes\/","title":{"rendered":"Aliases to Kill Linux Processes"},"content":{"rendered":"<p>As a developer I&#8217;m constantly restarting processes. For instance, if I have 2 Java Process (Server\/Web) and an Eclipse Java Process which makes 3 Java Processes. The problem is to kill only the server and web processes and leave the eclipse java process intact.<\/p>\n<p><strong>Solution 1 (The Hard and Manual approach):<\/strong><\/p>\n<blockquote><p>\n<em>Find the java processes and kill them manually<\/em><\/p>\n<p>ps -ef | grep java<br \/>\nkill -9 1<br \/>\nkill -9 2\n<\/p><\/blockquote>\n<p><strong>Solution 2 (The Simplified Approach &#8211; killjava):<\/strong><\/p>\n<blockquote><p>\n<em>Create an alias or run the following:<\/em><\/p>\n<p><strong>ps -A|grep java|sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221;|xargs kill -9<\/strong><\/p>\n<p><em>This will kill all java processes &#8211; which means you will need to <strong>restart eclipse<\/strong> each time you run this.<\/em>\n<\/p><\/blockquote>\n<p><strong>Solution 3 (The Tuned Approach &#8211; killweb):<\/strong><\/p>\n<blockquote><p>\n<em>Create an alias or run the following based on a keyword (say, Web process remote_debug port <strong>4096<\/strong>):<\/em><br \/>\n<strong>ps -A|grep java|sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221;  | xargs ps -p |<em> grep 4096<\/em> | sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221; | xargs kill -9<\/strong><\/p>\n<p><em>Create an alias or run the following based on a keyword (say, Server process remote_debug port <strong>2048<\/strong>):<\/em><br \/>\n<strong>ps -A|grep java|sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221;  | xargs ps -p |<em> grep 2048<\/em> | sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221; | xargs kill -9<\/strong><\/p>\n<p><em>This will kill only the specific processes you want to terminate.<\/em>\n<\/p><\/blockquote>\n<p><strong>Solution 4 (The BEST Way &#8211; Combine 1 and 2 in a single alias &#8211; killdebug):<\/strong><\/p>\n<blockquote><p>\n<em>Create an alias or run the following (Use <strong>egrep<\/strong> to look for multiple keywords above):<\/em><\/p>\n<p><strong>ps -A|grep java|sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221;  | xargs ps -p | <em>egrep &#8220;2048|4096&#8221;<\/em> | sed -e &#8220;s\/\\s*\\([0-9]*\\).*\/\\1\/&#8221; | xargs kill -9<\/strong><\/p>\n<p><em>This will kill all processes you WISH to terminate.<\/em>\n<\/p><\/blockquote>\n<p>I have aliases for Solutions 2, 3 and 4 depending on what I&#8217;m trying to do. So there you go &#8211; hope that helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a developer I&#8217;m constantly restarting processes. For instance, if I have 2 Java Process (Server\/Web) and an Eclipse Java Process which makes 3 Java Processes. The problem is to kill only the server and web processes and leave the eclipse java process intact. Solution 1 (The Hard and Manual approach): Find the java processes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,12],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/156"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":9,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":165,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/156\/revisions\/165"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}