The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pass arguments to called program ShellUser Shell Programming and Scripting 2 01-22-2008 05:34 AM
not able to kill find with kill -9 Amardeep UNIX for Dummies Questions & Answers 5 01-04-2007 01:49 PM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 01:24 PM
pass pid to kill using script hcclnoodles Shell Programming and Scripting 2 10-29-2004 09:19 AM
How to pass arguments to a function in a shell script? preetikate Shell Programming and Scripting 3 03-01-2004 12:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-24-2008
Registered User
 

Join Date: Apr 2008
Posts: 3
Pass Kill with arguments

Dude,

I want to kill a process, but the processid is in a text file. I have to read the text file for the process id and pass it as parameter to the kill command.

Example
$ cat prcid.txt
18650

I want to pass the value 18650 as a process id to kill command.

$ kill -9 <value read from the prcid.txt file>

The complete statement should be something like this...
$ cat prcid.txt | kill -9 <processid from txt file>

Thanks,
Muralee
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-24-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,102
kill -9 $(cat file)

The $(....) construct spawns a subshell and expands to the output of the shell, much like "$var" would expand to the content of the variable var.

You can even put several commands inside, like here:

Code:
if [ $(some_command >/dev/null ; print - $?) -gt 0 ] ; then
     print - "the return code was greater zero"
else
     print - "the return code was zero"
fi
I hope this helps.

bakunin
Reply With Quote
  #3 (permalink)  
Old 04-24-2008
Registered User
 

Join Date: Apr 2008
Posts: 3
Thanks for the reply. But things are not over....

To get more detailed, prcid.txt file has two process ids like below:
$ cat prcid.txt
18734 18733 prstat

First one (18734) is pid and the other is (18733) is ppid, so i want to pass arugment to kill as below to terminate the process and the parent process.

$ kill -9 pid -ppid.

I want to do some thing like below

$ kill -9 $(cat prcid.txt | cut -d" " -f1) -$(cut prcid.txt | cut -d" " -f2)

Thanks,
Muralee
Reply With Quote
  #4 (permalink)  
Old 04-24-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Didn't you just solve the problem yourself?
Reply With Quote
  #5 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 3
Thanks, problem solved

Thanks dudes problem solved.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0