LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-08-2010, 11:49 PM   #1
jaffd
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Rep: Reputation: 0
kill < file (Feeding kill from file), PID, <, awk, grep


Hi, In a script I have written, I have extracted a couple of processes by using (ps -ef) and (grep) and placed them in a file called (kill_PID). Then after using (awk) I am left with 2 PID's that I need to feed to (kill) command. Here is the scenario simplified:

File called (kill_PID) has 1 column with 2 values, lets give them the following values:

9645
9646

What do I need to add to my script in order to extract these to values from file (kill_PID) and feed them into kill command in order to kill both PID's.

I tried

kill < kill_PID

But this did not work. Feedback is appreciated.

Last edited by jaffd; 04-08-2010 at 11:52 PM. Reason: explain more
 
Old 04-09-2010, 12:09 AM   #2
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
You could use something like:

while read a ; do kill $a; done < kill_PID

You can use process names with some versions of kill. Also have you looked at 'killall'?
 
Old 04-09-2010, 01:29 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Or instead of having awk waste time putting them into a file just use it to execute the kill command:

Code:
awk '<whatever you have so far>{print | "kill " <number you got from previous stuff>}'
 
Old 04-09-2010, 04:07 PM   #4
jaffd
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Original Poster
Rep: Reputation: 0
bakdong > thank you for the (while) loop it fixed my problem and now I know how to read input from a file. I will also check out (killall).

grail > thanks, I thought about using (awk) all the way, but I need more time to master syntax and various options.
 
Old 04-09-2010, 05:06 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,688
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Quote:
Originally Posted by jaffd View Post
I have extracted a couple of processes by using (ps -ef) and (grep) and placed them in a file (..) Feedback is appreciated.
ps|grep|kill kludges may be necessary in some cases but next time try using 'pkill' instead?
 
  


Reply

Tags
awk, file, from, grep, input, kill, pid


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does kill -0 PID do? asihsh.nakul Linux - Newbie 16 11-14-2012 06:18 PM
kill <pid> does not do anything moskito01 Linux - General 9 08-25-2009 01:20 PM
What is the more easier way to check the pid and kill the pid cmx08 Linux - General 5 09-09-2008 11:57 PM
How do you do ps ax | grep mozilla | awk '{print "kill " $1}' pppaaarrrkkk Programming 4 03-19-2008 08:17 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration