Re: socko2: kill process by name
Re: socko2: kill process by name
- Subject: Re: socko2: kill process by name
- From: Mike Davis <email@hidden>
- Date: Thu, 7 Feb 2002 12:21:16 -0500
You can walk the process list using UNIX calls (see "man 3 sysctl" and
"man 2 kill").
int mib[ 3 ] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
size_t length;
struct kinfo_proc *theProcessInfoData;
struct kinfo_proc *theProcessInfo;
NSString *theProcessName;
pid_t theProcessID;
if( sysctl( mib, 3, NULL, &length, NULL, 0 ) == -1 ) return nil;
theProcessInfoData = (struct kinfo_proc*)malloc( length );
if( sysctl( mib, 3, theProcessInfoData, &length, NULL, 0 ) != -1 ) {
theProcessInfo = theProcessInfoData;
do {
theProcessName = [NSString
stringWithCString:theProcessInfo -> kp_proc.p_comm];
theProcessID = theProcessInfo -> kp_proc.p_pid;
fprintf( stderr, "%s = %d\n", [theProcessName cString],
(int)theProcessID );
theProcessInfo ++;
} while( (size_t)theProcessInfo < (size_t)theProcessInfoData +
length );
}
free( (void*)theProcessInfoData );
---
Only Mortal, the internet game server browser for MacOS X.
Visit:
http://homepage.mac.com/only_mortal/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.