Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > kill CLI utility from Cocoa

kill CLI utility from Cocoa
Thread Tools
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Jun 22, 2001, 06:26 PM
 
Hello there,

I need to search if a specific CLI utility is running, get its PID and then send it a kill command. In REALbasic I used something like this:

command = "top -l | grep utility | tail -c +3"
myShell.execute command
utilityPID = Left(myShell.result,3)

Is there a similar way to do this in Cocoa? Can I make AuthorizationExecuteWithPrivileges execute "top -l | grep utility | tail -c +3" in one step?

Thanks in advance

[ 06-22-2001: Message edited by: eevyl ]
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jun 23, 2001, 07:43 AM
 
You don't need to use NSTask to run 3rd party apps to kill stuff. Use the kill function. I think that it is in the kernel framework. It is like:

int kill(pid_t pid, int sig);

sig is the signal that you want to send. 9 is an unconditional kill. Note that you can't kill a process unless you own it, so an admin can't kill a root process unless they su to root.

pid is just the process id number. pid_t getpid(void); will get the pid of the calling process. I'm not sure how to get the pid's of other processes, unless you created them with fork().
     
eevyl  (op)
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Jun 23, 2001, 09:55 AM
 
Thanks for your reply Dalgo, but I already knew the kill stuff. I am asking for a way to ask for the PID of a known named CLI application. It is not created by a fork.

Thanks annyway.
     
Ambrosia - el Presidente
Join Date: Sep 2000
Location: Rochester, NY
Status: Offline
Reply With Quote
Jun 24, 2001, 01:06 AM
 
Originally posted by eevyl:
<STRONG>Thanks for your reply Dalgo, but I already knew the kill stuff. I am asking for a way to ask for the PID of a known named CLI application. It is not created by a fork.

Thanks annyway.</STRONG>
If you care to use Carbon, the process manager will let you do this kind of thing. If not, I'm sure there are Mach/BSD-level calls for iterating through running processes.
Andrew Welch / el Presidente / Ambrosia Software, Inc.
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jun 25, 2001, 11:05 AM
 
Using ps -axc is probably better than using top, but anyways...

Look at the sysctl() function (man 3 sysctl). It is an interface to get at a lot of kernel information, including the process list.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2