OT - shell script to kill a process

Chris Sheffield cmsheffield at gmail.com
Tue Jul 10 11:28:01 EDT 2007


Well, Ken. It turns out I think I need to go with your method. The  
'killall' command is definitely more concise, but it turns out that I  
am going to have to do a partial search on the path to the process  
exe just to make sure I get the right one, and killall doesn't seem  
to allow that.

I've got another question for you though. It concerns the 'cut -d\  - 
f2' part of this. This doesn't seem to be working correctly. Can you  
explain more what's supposed to happen here? It seems to just be  
returning an empty string, so a valid pid is never passed on. I've  
tried it using TextEdit as well as using my own process in the  
command. Any thoughts?

Thanks,
Chris


On Jul 9, 2007, at 4:03 PM, Ken Ray wrote:

> On Mon, 9 Jul 2007 14:46:32 -0600, Chris Sheffield wrote:
>
>> My Unix scripting knowledge leaves a bit to be desired, so I thought
>> I'd ask here for some help.
>>
>> I have a Vise installer for OS X that needs to check for and kill our
>> own process if it's running. The installer will be authenticated when
>> running. I need a shell script that I can execute from within the
>> installer that will determine, by name, if a given process is
>> running, and then kill it dead if so. Can someone help?
>
> Well, it's ugly, but you can execute this:
>
> ps -awx | grep 'TextEdit' | grep -v 'grep' | cut -d\  -f2 | xargs -I
> pid kill -9 pid
>
> A few notes:
>   - I'm using TextEdit as the app I want to close - replace your app
> name here (to see what I'm parsing, execute 'ps -awx' in the Terminal
> by itself).
>   - This is all one line, no returns here
>   - There are actually two spaces after the "d\" and before the "-f2".
>
> Here's what it means (for those wondering):
>
>   (ps -awx) = Get a list of all currently running processes with full
> path names.
>
>   ( | grep 'TextEdit') = Pipe the result to 'grep' (the regex engine)
> and return any lines that contain 'TextEdit'. This will return TWO
> lines, one with the path to TextEdit on it, and the other one is the
> actual 'grep' call that is trying to find 'TextEdit'.
>
>   ( | grep -v 'grep') = Pipe the result to 'grep' again, but this time
> ignore any lines that have 'grep' in it. (Sneaky!)
>
>   ( cut -d\  -f2) = Extract ("cut") the second space-delimited "word"
> in the resulting string ("-d" means use a delimiter, "\ " is the
> delimiter to use (has to be escaped because spaces normally signify a
> change of parameters, etc. on the command line), "-f2" means look for
> the second space-delimited "field" in the string)
>
>   ( | xargs -I pid kill -9 pid) = Pipe the result (the process ID)  
> into
> a variable called 'pid' that will replace the argument variable 'pid'
> in the call to the 'kill' command (normally to kill a process it would
> look like "kill -9 1012")).
>
> HTH,
>
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: kray at sonsothunder.com
> Web Site: http://www.sonsothunder.com/
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

------------------------------------------
Chris Sheffield
Read Naturally
The Fluency Company
http://www.readnaturally.com
------------------------------------------





More information about the use-livecode mailing list