 |
 |
kill CLI utility from Cocoa
|
 |
|
 |
|
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status:
Offline
|
|
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
|
|
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().
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status:
Offline
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|