{"id":35,"date":"2007-10-08T01:52:23","date_gmt":"2007-10-07T17:52:23","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/loop-kill-mutiple-pid-on-bourne-shell\/"},"modified":"2007-10-08T01:52:23","modified_gmt":"2007-10-07T17:52:23","slug":"loop-kill-mutiple-pid-on-bourne-shell","status":"publish","type":"post","link":"https:\/\/www.sysadmindayph.com\/blog\/loop-kill-mutiple-pid-on-bourne-shell\/","title":{"rendered":"Loop Kill Mutiple PID On Bourne Shell"},"content":{"rendered":"<p>Just want to document it here. A colleague request to kill multiple PID owned by different users. They don&#8217;t have any special privilege to kill process other than their own.<\/p>\n<p>Here&#8217;s a simple <em>for&#8230;loop<\/em> script that will look for and kill each PID it found.<\/p>\n<blockquote><p> #!\/bin\/sh -x<br \/>\nps -ef | grep nobody | awk &#8216;{print $2}&#8217; &gt; \/tmp\/PID<br \/>\nfilePID=&#8221;\/tmp\/PID&#8221;<br \/>\nfor PID in `cat $filePID`<br \/>\ndo<br \/>\nkill -9 $PID<br \/>\ndone<br \/>\n#<\/p><\/blockquote>\n<p>Line 1, tells which shell will execute the script<\/p>\n<p>Line 2, gets all the PID to be killed and store them on a file.<\/p>\n<p>Line 3, assigns a variable for the file<\/p>\n<p>Line 4 to 7 is the for&#8230;do loop which basically gets each line on the file, store the value on $PID and then kill whatever value is in it on line 6.<\/p>\n<p>Yucky script. Post a better one.<\/p>\n<p>Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just want to document it here. A colleague request to kill multiple PID owned by different users. They don&#8217;t have any special privilege to kill process other than their own. Here&#8217;s a simple for&#8230;loop script &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,17,5,3],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-linux","category-scripting","category-solaris","category-unix"],"_links":{"self":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}